0% found this document useful (0 votes)
38 views1 page

G11 DS Tutorial 1

The document contains a tutorial on data structures with 5 problems: 1) Find the min and max of an array, search for an element, and sort the array. 2) Find the matrix multiplication of two given matrices. 3) Derive the address of an element in a 2D array stored in row-major order. 4) Find the sum of elements of a defined n×n array. 5) Derive the index formula for elements of a lower triangular matrix stored in a 1D array.

Uploaded by

Lone Survivor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views1 page

G11 DS Tutorial 1

The document contains a tutorial on data structures with 5 problems: 1) Find the min and max of an array, search for an element, and sort the array. 2) Find the matrix multiplication of two given matrices. 3) Derive the address of an element in a 2D array stored in row-major order. 4) Find the sum of elements of a defined n×n array. 5) Derive the index formula for elements of a lower triangular matrix stored in a 1D array.

Uploaded by

Lone Survivor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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