Vous êtes sur la page 1sur 4

QUIZ QUESTIONS

Design and Analysis of Algorithms

1. O( n) , where O(n) stands for Big-oh of n is:


1 k n
1. O(n2 )
2. O(n)
3. O(n3 )
4. None

Answer: 1
2. Suppose T ( n ) =2T ( n2 )+ n ,T ( 0 )=T ( 1) =1 , which one of the following is
false
1. T ( n ) =O ( n2 )
2. T ( n ) =(nlogn)
3. T ( n ) = ( n2 )
4. T ( n ) =O(nlogn)

Answer: C
3. How many invocations are there by the following recursive function for the
call: fun(fun (5)) ?
Int fun(int N)
{
if ( N < 3 )
return 1;
else
return (fun (N-1) + fun (N-3) + 1)
}
1. 24
2. 30
3. 10
4. 0

Answer: 1
4. Consider the pseudo code for the Towers of Hanoi implementation
Void TOH(int n, int L int R, int M)
{
if ( n != 0 )
{
TOH ( n-1, L, R, M)
Print Move L to R
TOH (n-1, M, L, R)
}
}

After how many invocations of TOH, the first disc move will take place when
the number of discs n = 3.
1. 1
2. 4
3. 5
4. 7

Answer: 2
5. Consider the quicksort algorithm. Suppose there is a procedure for finding a
pivot element, which splits the list two sub-lists each of which contains at least
one-fifth of the elements. Let T ( n) be the number of comparisons required
to sort n elements. Which one among the following is correct
n
1. T ( n ) =2T () 5
+n

n 4n
2. T ( n ) =T () ( )
5
+T
5
+n

4n
3. T ( n ) =2T ( ) 5
+n

n
4. T ( n ) =2T () 2
+n

Answer: 2
6. Which of the following sorting algorithm has the lowest worst-case
complexity?
1. Merge sort
2. Bubble sort
3. Quick sort
4. Selection sort

Answer: 1
7. Which of the following in place sorting algorithm needs minimum number of
swaps?
1. Quick sort
2. Insertion sort
3. Selection sort
4. Heap sort

Answer: 3
8. In quicksort, for sorting n elements, the n/4th smallest element is chosen as the
pivot. If partition procedure for placing the pivot is taking O(n) time, what
is the worst case complexity of quicksort for this scenario?
1. (n)
2. ( nlogn )
3. ( n2 )
4. (n2 logn)

Answer: 2
9. For merging two sorted lists of size m and n into a sorted list of size
m+ n , the required comparisons are of:
1. O(m)
2. O(n)
3. O ( m+n )
4. O(logm+logn)

Answer: 3
10. Quick sort is run in two inputs shown below to sort in ascending order:
1. 1,2, , n and (ii) n , n1, , 2,1
Let C1 and C2 be the number of comparisons made for the inputs (i) and (ii)
respectively. Then which one is true among the following:
1. C 1<C 2
2. C 1>C 2
3. C 1=C 2
4. Cannot say

Answer: 3
11. Merge sort uses
1. Divide and Conquer strategy
2. Backtracking
3. Heuristic
4. Greedy

Answer: 1
12. Quick sort uses
1. Divide and Conquer strategy
2. Backtracking
3. Heuristic
4. Greedy

Answer: 1
13. Binary search uses
1. Divide and Conquer strategy
2. Backtracking
3. Heuristic
4. Greedy

Answer: 1
14. For a list of n sorted elements if we want to search an element using binary
and ternary search (the entire list is divided into 3 nearly equal halves while in
binary search it will be 2 halves before searching). If B 1 is the number of
comparisons for binary search and T 1 is the number of comparisons for
ternary search, then which of the following relation will hold true:
1. B1 > T1
2. B1 < T1
3. B1 = T1
4. Cannot say

Answer: 2
15. What is asymptotic upper bound of the following recurrence relation:
n
()
T ( n ) =8 T
2
+ ( n2 ) ,T (1 ) =1

1. O(n)
2. O ( n2.8 )
3. O ( n3 )
4. 23

Answer: 4
16.

Vous aimerez peut-être aussi