Tab DAA - S1 - 1446 With Key - MIDTERM SOlution
Tab DAA - S1 - 1446 With Key - MIDTERM SOlution
d. None
if (n==1)
return 2;
else
a. T(1) =c
T(n) = b+ 2T(n/2)
b. T(0) =c
T(n) = b+ 2T(n/2)
c. T(1) =c
T(n) = b+ T(n/2)
d. None
6. Probabilistic algorithm
Page 1 of 4
a. Randomize Quick Sort b. Insertion Sort c. Merge Sort d. None
8. When the array is sorted or almost sorted is better to use ……. Sort to achieve the best
performance.
Question 2: True/False 1 X7 = 7
a.True b. False
12. Running time of Quicksort when levels alternate between good and bad splits is O(n)
a.True b. False
13. Linear Search: A search traverses the collection until the desired element is found:
a.True b. False
a.True b. False
a.True b. False
a.True b. False
Page 2 of 4
17. Combine: The subproblem solution to get the solution to the original problem
a.True b. False
18. Form and solve the recurrence relation for the running time of factorial method and
hence determine its big-O complexity:
if (n == 0)
return 1;
else
Answer
Page 3 of 4
19. Given a sorted array, how many comparisons are required to find the element 42 using
Binary Search? Write all the steps
7 12 42 59 71 86 104 212
42 found – in 3 comparisons
Page 4 of 4