CS202 Mid Sem
CS202 Mid Sem
(a) What would be the lower bound of sorting n3 elements in the com-
parison model?
(b) What does RAM stand for in the term RAM model of computation?
(c) What would be the time taken to find the GCD of two integers x and
y using Euclidean algorithm?
(d) If f (x) = (ax + b)n and g(x) = p ∗ xn/2 , what would be the most
appropriate asymptotic relation between f (x) and g(x).
(e) What steps need to be performed in order to insert a node X between
two nodes A and B which are adjacent in a linked list. A and B are
the second and third nodes of the linked list respectively.
2. Rank the following six functions by order of growth; that is, find an
arrangement g1 , g2 , ..., g6 of the functions satisfying g1 = O(g2 ), g2 =
O(g3 ), ..., g5 = O(g6 ). 4 marks
∗ √
(a) 2log n ; log(log∗ n); ( 2)log n ; n!; n3 and (log n)!
n 1
(b) 1.7n ; log2 n ; 22 ; log(n10 ); n log n and n2.5
Note:- log∗ n (usually read “log star”), is the number of times the loga-
rithm function must be iteratively applied before the result is less than or
equal to 1.
5. 4 marks
(a) Give an O(n lg k)-time algorithm to merge k sorted lists (which are
not necessarily of same length) into one sorted list, where n is the
total number of elements in all the input lists.
1
(b) Write the pseudocode of randomized quicksort, which happens to be
stable.
6. You are given an array of integers, where different integers may have
different numbers of digits, but the total number of digits over all the
integers in the array is n.
Show how to sort the array in O(n) time. 3 marks
7. Write an O(n)-time nonrecursive procedure that, given an n-node binary
tree, prints out the key of each node. Use no more than constant extra
space outside of the tree itself and do not modify the tree, even
temporarily, during the procedure. 2 marks