Design and Analysis of Algorithms (Ict 2222)
Design and Analysis of Algorithms (Ict 2222)
MCQ
Answer all the questions. Section Duration: 20 mins
5 2 4 3
2) Consider the array A= {4,1,3,2,16,9,10,14,8,7}, After building max-heap from the array A, the depth (0.5)
of the heap and right child of root are -------- and ----------- respectively.
3) When the balance factor of X is 2 due to insertion of nodes at either B1 or B2, a rotation would result (0.5)
to
B2 is the left B2 is the left subtree of B1 is the left subtree of B2 is the right subtree of
subtree of Y right child of Z right child of Z left child of Z
4) How does a 2-3 tree balances when the root node has to be deleted? (0.5)
int main() {
int x, y, m, n;
Page 1 of 4
scanf ("%d %d", &x, &y); /* x > 0 and y > 0 */
m = x; n = y;
while (m != n)
if(m>n)
m = m - n;
else
n = n - m;
printf("%d", n); }
x + y using
x mod y using The greatest common The least common
repeated
repeated subtraction divisor of x and y multiple of x and y
subtraction
6) Consider the following pairs of functions f(n), g(n). Which pair the functions are such, that f(n) is (0.5)
O(g(n)) and g(n) is not O(f(n)) ?
f(n)=n3 g(n) = n2 log(n2 f(n)=log(n) g(n) = 10 f(n)=1 g(n) = log f(n)=n2 g(n) = 10n
) logn n logn
7) Consider the following array: A[]= {12, 11, 13, 5, 6}. Apply the insertion sort algorithm to sort the (0.5)
array. Assuming that the cost associated with each swap is 25 rupees, what will be the total cost of
the insertion sort when all the elements are sorted?
50
200 175 150
8) Which of the following analogies best represents the process of sorting the numbers (15, 3, 28, 10, (0.5)
6, 19, 25) in ascending order using bubble sort?
9) Assume that a mergesort algorithm in the worst case takes 30 seconds for an input of size 64. (0.5)
Which of the following most closely approximates the maximum input size of a problem that can be
solved in 6 minutes?
10) If one uses a straight two-way merge sort algorithm to sort the following elements in ascending (0.5)
order: 20, 47, 15, 8, 9, 4, 40, 30, 12, 17 Then, the order of these elements after the second pass of
the algorithm is
8, 15, 20, 47, 4, 9, 30, 8, 9, 15, 20, 47, 4, 12, 15, 20, 47, 4, 8, 9, 12, 4, 8, 9, 15, 20, 47, 12,
40, 12, 17 7, 30, 40 30, 40, 17 17, 30, 40
DESCRIPTIVE
Page 2 of 4
Answer all the questions.
11) Suppose a quick sort algorithm is applied for sorting n elements, and at level, the pivot element (2)
divides the array of size n into two subarrays of size (n/4) and (3n/4). Analyze the given scenario
and write the recurrence relation. Also, solve the framed recurrence relation using the substitution
method and identify which case (best/average/worst) this scenario belongs.
12) Prove or Disprove using formal definitions of asymptotic notations and limit theory (3)
is false
is true.
if (y == 0) return 0;
if (b == 0) return 1;
15) Imagine your friend is trying to find a specific "key" among many keys with unique "patterns" on (3)
them. Develop an algorithm inspired by you to systematically search for the right key by comparing
its pattern and analyze the time complexity for the given problem.
16) The time required for dividing the main problem into sub-problems (Td ) and the time required for (3)
merging the solutions of the subproblems (Tm) are important in deciding the time complexity of an
algorithm that follows the divide-and-conquer approach. Apply your understanding from the divide-
and-conquer approach and establish the relation between Td and Tm (i.e., Td> Tm or Tm> Td or
Td=Tm) for the (i) Merge Sort (ii) Binary Search (iii) Matrix Multiplication.
17) The airline's flight operations department receives a daily list of upcoming flight departure times for (4)
various destinations. The flight operations department receives the following unsorted list of flight
departure times:
To enhance customer satisfaction, use the Balanced tree structure to get the sorted Departure
Page 3 of 4
Schedule. Further Discuss the time complexity of your solution.
18) Justify how the transform and conquer strategy helps to maintain the balance factor of either 0, -1, (4)
or 1 at every node during the insertion of the following elements: 3, 2, 1, 4, 5, 6, 7, 16, 15, 14 into a
binary tree.
-----End-----
Page 4 of 4