Skip to main content

PROBLEM SHEET 5

This problem sheet was created by Sir Narasimhan T, Assistant Professor, IT Department LBS College of Engineering, Kasaragod.

The softcopy in .pdf is available here. There is  a bit more in the file.

1) Calculate the mean, variance and standard deviation of a set of numbers.

2) A m × n matrix M is said to have a saddle point if there is an entry M[i][j] such that it is the smallest value in row i and the largest value in column j. For example, consider the matrix:
20   30   40
56   78   45
1   2   3
Here 45 is the saddle point because it is the smallest in row1 but largest in column2. Given a matrix, find the saddle point if it exists.

3) Determine the norm of a matrix. Norm is defined as the square root of the sum of the squares of matrix elements. A sample input and output is shown below:
Enter the size of matrix
2  3
Enter 6 elements
1  2  3  4  5  6
The matrix is
1  2  3
4  5  6
The norm is 9.539392

4) A magic square of order n is a square matrix of integers from 1 to n^2 arranged randomly in a square grid fashion. The peculiarity of magic square is that the numbers in each row, and in each column, and the numbers in the forward and backward diagonals, all add to the same constant M where M =
n(n^2+1)/2.  For example, the matrix
2  7  6
9  5  1
4  3  8
is a magic square since each row, each column and the two diagonals add to (3×10)/2 =15. Write a program to input a square matrix from the user and that checks whether it is a magic square or not. The order of the matrix should also be input.

5) Convert decimal number to binary.

6) Interchange two rows in a matrix. Sample input and output is shown below
Enter number of rows
3
Enter number of columns
4
Enter the elements
4 8 12 16 1 2 3 4 3 9 12 18
The input matrix is
4 8 12 16
1 2 3 4
3 9 12 18
Which two rows you want to interchange?
0 2
The matrix after exchanging row 0 and row 2 is
3 9 12 18
1 2 3 4
4 8 12 16

7) The following is known as Pascal’s triangle.
1
1  1
1  2  1
1  3  3  1
1  4  6  4  1
1  5  10  10  5  1

Any element p[i][j] (except the 1’s at the left and right ends) in this triangle p is given by
p[i][j] = p[i-1][j-1] + p[i-1][j]
Input the number of rows and print the Pascal triangle.

8)Interchange two columns in a matrix. Sample input and output is shown below
Enter number of rows
4
Enter number of columns
3
Enter the elements
4 8 12 16 1 2 3 4 3 9 12 18
The input matrix is
4 8 12
16 1 2
3 4 3
9 12 18
Which two columns you want to interchange?
1 2
The matrix after exchanging column 1 and column 2 is
4 12 8
16 2 1
3 3 4
9 18 12

9) Input a string and print all its prefixes and suffixes. A sample input and output is given below:
Enter a string
cprogram
The prefixes of cprogram are
cprogram
cprogra
cprogr
cprog
cpro
cpr
cp
c
The suffixes of cprogram are
cprogram
program
rogram
ogram
gram
ram
am
m

10) A square matrix is called lower triangular if all the entries above the main diagonal are zero. Conversely a square matrix is called upper triangular if all the entries below the main diagonal are zero. A matrix that is both upper and lower triangular is a diagonal matrix. (A diagonal matrix will have non zero entries only on the main diagonal). Find whether an input matrix falls under any of these categories.

11) Write a program that takes nouns and that forms their plurals on the basis of these rules:
• If the noun ends in “y”,remove the y and add “ies”
• If the noun ends in “s”, “ch” or “sh”, add “es”.
• In all other cases just add “s”.
Print each noun and its plural. Sample input and output is listed here:
Enter how many nouns
5
Enter the nouns
chair
dairy
dish
church
circus
The nouns and their plurals are
chair - chairs
dairy - dairies
dish - dishes
church - churches
circus - circuses

12) Perform addition, subtraction and transpose operations on matrices. The user will enter ’a’ for addition,’s’ for subtraction and ’t’ for transpose. Only if the user enters ’a’ or ’s’, the second matrix needs to be input.

13) The alphabetic distance between 2 letters x and y is defined by assigning ’A’=1, ’B’=2, ... ’Z’=26. Then the distance is y − x if y ≥ x, and (y + 26) − x if y < x. For instance, the alphabetic distance between ’B’ and ’D’ is 4 − 2 = 2, while the distance between ’D’ and
’B’ is (2 + 26) − 4 = 24. Given two words of equal length, the distance between them is the sum of alphabetic distances between the corresponding characters. Your aim is to input two words and print the distance between them.
Sample input and output - 1
Enter the words
AAAA ABCD
Distance between AAAA and ABCD is 6
Sample input and output - 2
Enter the words
DEADLY ULTIMO
Distance between DEADLY and ULTIMO is 65
[Note above that 6 = 0 + 1 + 2 + 3 and 65 = 17 + 7 + 19 + 5 + 1 + 16]

14) Write a program to form a Latin square. A Latin square is represented by an m × m two dimensional array filled with m different characters such that no element gets repeated either in the row or in the column. For example, if m = 4; the chosen characters are A, B, C, D and the first row is A B C D , then second row cannot have A as the first element as every column should have unique elements. Input the order m and the first row of the matrix and print the Latin square. A sample input and output is shown below:
Enter the order
3
Enter the first row
C A B
The Latin square is
C A B
A B C
B C A

15) Caesar cipher is a way of creating a code word (secret word) from a given word by substituting each character in the word with another character which is obtained by adding m (a constant which is called key) to the original character. For example if the original character is ’A’ and the value of m is 3, then the substituted character will be ’D’, which is A + 3. Assume that
the input word contains only upper case letters (ASCII 65-90). The following procedure can be used to obtain the codeword:-
• Take each character in the word and add m to it.
• If the number obtained is greater than 90, subtract 90 from the number. Let the result
be r. Now add r-1 to 65. In this way, the substituted character will always lie between A
and Z.
A sample input and output is shown below:
Enter the word
QWERTY
Enter the key
4
The codeword is
UAIVXC

16) Super Mario is studying how to use a mysterious Power Square. The Power Square is an n × n matrix with integer values between 0 and n^2−1. A number y is a neighbour of another number x in the Power Square if y is directly above or below x, or directly to the left or right of x.
Note that some values in the Power Square need not have all the four neighbours. Mario wants you to help him write a program that when given a number x in the Power Square, displays the Power Square and all the neighbours of x. Two sets of sample input and output are shown below:

SET 1
Value of n please?
3
9 Values please?
8 7 6 5 4 3 2 1 0
Neighbours of whom?
7
Power Square is
8 7 6
5 4 3
2 1 0
The neighbours of 7 are
8 6 4

SET 2
Value of n please?
4
16 Values please?
1 5 9 12 0 2 8 10 6 11 15 14 4 7 3 13
Neighbours of whom?
2
Power Square is
1 5 9 12
0 2 8 10
6 11 15 14
4 7 3 13
The neighbours of 2 are
0 5 8 11

Comments

Popular posts from this blog

SNIFF GSM USING HACKRFX

​TOOLS  USED: •  ha ckrf_kali • brategnuradio-companion • gr-gsmgqrx • wireshark INSTALL REQUIREMENTS: First thing, you want to make sure you have all the required software installed, you can install most of them and their dependencies using your distribution package manager. Let’s start with the libraries and tools for the hackrf itself, on a Debian/Ubuntu distro you’ll install them like so: sudo  apt-get install  hackrf   libhackrf -dev libhackrf0 Once these libraries are installed, you can plug your hackrf into one of your USB ports and execute the  hackrf_info  command, at this point you should see something like the following: # hackrf_info Found  HackRF  board. Board ID Number: 2 ( HackRF  One) Firmware Version: 2014.08.1 Part ID Number: 0x00574746 0x00574746 Serial Number: 0x00000000 0x00000000 0x14d463dc 0x2f4339e1 You will now install  gnuradio  which is the software we’ll use to decode the RF signals,  gqrx  a tool to visualize signal power on certain frequencies

MORE ABOUT RANSOMWARES. PART 1

 Not long ago, a man committed suicide after an automatically generated notice from a computer virus threatened him with jail unless he paid a ransom thousands of dollars. The year was 2014. As incredible as the story seems, it marked the first known time a computer virus actually killed somebody. The next generations stole cash from users around the globe, and Cryptolocker raised the stakes – holding data of hundreds of thousands of users hostage. Despite successive short-lived take downs, the malware has made a comeback as CTB (Curve-Tor-Bitcoin) Locker. This challenging breed of malware is continuously improving, reaching new levels of complexity as smartphones and tablets are increasingly used to store crucial personal and enterprise-level documents. Bitdefender, the anti-malware solutions provider, zooms in on the subject to show how this type of virus works and to tell users how to prevent being locked out and extorted. What is ransomware? Ransomware is a type of malware th

TERMINAL ON ANDROID- TERMUX

Let Termux be our topic today. It is an Android application which is a Terminal Emulator distributed by Fredrik Fornwall. It creates exactly the same working environment of Linux Terminal on Android. Take a try. It can be installed from Google Play Store. Navigate from here . After the environment is set, go to App settings from the System Settings and give the App Storage permission.  Basic linux command like cd, ls, pwd, cat, touch and many more or almost all can be made here on this prompt. To install packages like Python or Pip type in packages install <packageName> It's that simple.  Similarly, to execute a program or a package, type <packageName> then, the corresponding help will be appear. Rest is with you. This is how an installation screen appears to be.. Now, about storage. As the initial step, type in termux-setup-storage Typing pwd gives the current working directory and it will be something like /data/data/com.termux/files/