You are on page 1of 1

Data Structure Tutorial, B.

Tech 2nd Semester

Tutorial 1

1. Consider an array A = {10, 1, 5, -5, 6, 99, 75, 34, 78, 53}. Do the followings:

(a) Write an algorithm to find the smallest number and largest number in A respectively.
• Run the above algorithm step by step on A
(b) To search a given element a in A.
• Run the above algorithm step by step on A
• Do the worst case, the average case, and best case analysis on the algorithm
(c) Write an algorithm to sort A
• Run the above algorithm step by step on A
• Do the worst case, the average case, and best case analysis on the algorithm

2. Write an algorithm to find the matrix multiplication for two matrices A and B
   
 1 5 3 0 1 2
• Given, A = 3 1 2 and B = 2 5 5 . Compute the AB and BA respec-
−1 2 1 5 1 4
   
tively.

3. Let A be a two-dimensional array declared as follows: A: array [ 1... 10] [1... 15] of
integer; Assuming that each integer takes one memory locations the array is stored in
row-major order and the first element of the array is stored at location 100, what is the
address of the element A[i] [j]?

4. An n × n array V is defined as follows

V (i, j) = i − j ∀i,j

What will be the sum of the elements of the array V ? Justify your answer.

5. In a compact single-dimensional array representation for lower triangular matrices (i.e all
the elements above the diagonal are zero) of size n × n, non-zero elements (i.e., elements
of the lower triangle) of each row are stored one after another, starting from the first row,
the index of the (i, j) th element of the lower triangular matrix in this new representation
is .

—– Page 1 of 1 —–

You might also like