Professional Documents
Culture Documents
GLA University, Mathura Design and Analysis of Algorithms Tutorial-1 B.Tech-V Semester
GLA University, Mathura Design and Analysis of Algorithms Tutorial-1 B.Tech-V Semester
Consider sorting n numbers stored in array A by first finding the smallest element
of A and exchanging it with the element in A[1]. Then find the second smallest
element of A, and exchange it with A[2]. Continue in this manner for the first n - 1
elements of A. Write pseudocode for this algorithm. Give the best-case and worstcase running times of selection sort in -notation.
2.
Write the INSERTION-SORT procedure to sort into nonincreasing instead of
nondecreasing.
3.
Let f(n) and g(n) be asymptotically nonnegative functions. Using the basic
definition of -notation, prove that max(f(n), g(n)) = (f(n) + g(n)).
4.
5.
6. List of n strings, each of length n, is sorted into lexicographic order using the mergesort algorithm. The worst case running time of this computation is
O (n log n) (B) O (n2 log n) (C) O (n2 + log n) (D) O (n2)
7. Which of the
n^(1/2)
(C) 2^(n/2)
(D) 2^(n!)
(A) O(n)
(1)
( B) O(log n)
( D)
13. Which one of the following is the tightest upper bound that
represents the number of swaps required to sort n numbers using selection
sort?
(A) O(log n)
(B) O(n)
(C) O(n log n)
(D)
O(n2)
14. Consider the following function:
The return value of the function is
(A) (n2)
(B) (n2log n)
(D)(n3logn)
15.
(C) (n3)