DS Ass I
DS Ass I
DS Ass I
Max.
For each of the following six program fragments: find worst case time
complexity. Give reasons for your answer. ( 1 + 1 + 1 + 1 + 3 + 3 )
(a) sum = 0;
for( i=0; i<n; i++ )
sum++;
(b) sum = 0;
for( i=0; i<n; i++ )
for( j=0; j<n; j++ )
sum++;
(d) sum = 0;
for( i=0; i<n; i++ )
for( j=0; j<i; j++ )
sum++;
(e) sum = 0;
for( i=0; i<n; i++ )
for( j=0; j<i*i; j++ )
for( k=0; k<j; k++)
sum++;
(c) sum = 0;
for( i=0; i<n; i+
+)
for( j=0; j<n*n;
j++ )
sum++;
(f) sum = 0;
for( i=1; i<n; i+
+)
for( j=1; j<i*i;
j++ )
if( j%1 == 0 )
for( k=0; k<j;
k++ )
sum++;
II.
III.
IV.
You are given a linked list, L, and another linked list, P, containing
integers, sorted in ascending order. The operation print_lots(L,P) will
print the elements in L that are in positions specified by P. For instance,
if P = 1, 3, 4, 6, the first, third, fourth, and sixth elements in L are
printed. Write the routine print_lots(L,P). You should use only the basic
list operations. What is the running time of your routine?
V.
Given two lists, L1 and L2, write a procedure to merge two lists using
only the basic list operations.
VI.
(4+
Given a list L1 write a procedure to sort the list using only the basic list
operations.
(b) Depth of a
Tree
(1+
II.
III.
IV.
V.
VI.
a) Write a C program to insert an element into AVL Tree.
(5+5)
b) Derive expression for average internal path length of a Binary
Search Tree.
(5+