Professional Documents
Culture Documents
1. Is it possible to measure the efficiency of an algorithm which does not depend on the
state of current technology? If yes, how?
2. An algorithm is made up of two independent time complexities f (n) and g (n). Then the
complexities of the algorithm is in the order of
a. f(n) x g(n)
b. Max ( f(n),g(n))
c. Min (f(n),g(n))
d. f(n) + g(n)
4. Which algorithm has same average, worst case and best case time :
(A) Binary search (B) Maximum of n numbers
(C) Quick sort (D) Searching a singly linked list
5. Arrange the following in the increasing order of time complexity: O(n2), O(n log n),
O(2n), O(log n)
Because this the summation of the first ‘n’ numbers, that is n(n+1)/2 => ( n2+n)/2 =>
then by ignoring the lower order terms and the constants this becomes n2.
7. Adding an element to an array that does not allow duplicates requires how many
comparisons in the worst case?
8. What is the significance of asymptotic notations? Show that the algorithm to find the
maximum from an array is θ(n)
10. What is the format of a recurrence relation? Solve the following recurrence relation using
Substitution method. T(n) = 4T(n/3) + n
14. Write the control abstraction for Divide and Conquer Strategy.
In divide and conquer approach, a problem is divided into smaller problems, then the
smaller problems are solved independently, and finally the solutions of smaller problems
are combined into a solution for the large problem.
Divide the problem into a number of sub-problems that are smaller instances of the same
problem.
Conquer the sub-problems by solving them recursively. If they are small enough, solve the
sub-problems as base cases.
Combine the solutions to the sub-problems into the solution for the original problem.
17. In what manner will you arrange the following elements that if the quick sort is
performed on this new sequence, the sorting time becomes maximum i.e. of order O(n2)
where n represents the number of elements in the sequence. Justify your answer.
12, 5, 7, 10, 17, 18, 23, 8, 6, 13
18. The lower bound for comparison based sorting methods is O(n lg n). Is it possible to sort
faster than O(n lg n)? Justify your answer.
19. Consider the following program segment. What is the Space complexity?
Begin
i) i=0;
ii) S=0;
iii) S=s+1;
iv) Return s;
End
21. Randomised algorithms are also called as __________________ and whose behavior is
dependent on _______________ in decision making as part of its logic
23. Use the Master method to find T(n) = Θ(?) in each of the following cases:
a) T(n) = 7T(n/2) + n2
b) T(n) = 4T(n/2) + n2
c) T(n) = 2T(n/3) + n3
25. Apply merge sort for the following list of elements: 6, 3, 7, 8, 2, 4, 5, 1 . Analyze the
time complexity of Merge Sort
26. Consider the following four matrices whose orders are given and perform chain matrix
multiplication using the dynamic programming approach
Matrix A1 A2 A3 A4
size 2x2 2x3 3x4 4x2
65 70 75 80 85 60 55 50 45
33. Solve T(n) = 3T(n/4) + cn2 using recursion-tree method and Substitution method
34.