Daa (Mock Test - 1)
Daa (Mock Test - 1)
Q1) The preorder traversal of a binary search tree is 25, 15, 10, 4, 12, 24, 50, 35, 31, 44, 70,
66 and 90. Find the postorder traversal of the tree?
Q2) If cost of every subset is 1 then we can solve set cover problem in polynomial time. If it is
true then justify your answer.
Q3) Let A1, A2, A3 and A4 be four matrices of dimensions 10*5, 5*20, 20*10 and 10*5
respectively. The minimum number of scalar multiplications required to find the product
A1*A2*A3*A4 using the basic matrix multiplication method is_________. Also find how
many ways are there to multiply matrix.
Q4) Let x is the cost of MST G (V, E) and y is the cost of MST G (V, E2),
where E2 means:
If w (u, v) ∈ E then w2 (u, v) ∈ E2 and w ∈ real numbers. (Consider w is the weight/cost)
Find relationship between x and y for all cases.
Q5) Let P be quicksort program to sort numbers in ascending order using the first element as
the pivot. Let t1 and t2 be the number of comparisons made by P for the
inputs [1 2 3 4 5] and [4 1 5 3 2] respectively. Which one of the following holds?
a) t1<t2 b) t1=5 c) t1=t2 d) t1>t2
T(n) = 4T (n/3) + n2
Q2) Consider two strings A = “abbaccda” and B = “abcaa” consider "x"be length of the longest
common subsequence between A and B and “x” be the number of distinct such longest
common subsequences between A and B. Then 10x+ 2 is ________.
Q3) Imagine you have a magical deck of numbered cards: 42, 8, 23, 56, 34, 15, 9, 67. You
decide to sort them in ascending order, but here's the twist—you must use bubble sort
first and count the number of swaps (X). Then, you switch to selection sort and count the
total number of comparisons (Y).Now, for the grand finale: What is the value of X+Y?
Q4) Suppose there are 4 sorted list of 16 elements each. If we merge these lists into a single
sorted list of 64 elements. Find the key comparisons that are needed in the worst case and
best case using an efficient algorithm (Optimal merge pattern) along with time.
Q5) Let G = (V, E) be a connected, weighted graph. Let T1 and T2 be two MSTs of G and α ∈
R. Then the number of edges in T1 of weight α is the same as the number of edges in T2
of weight α.
Q1) When do Dijkstra and the bellman ford algorithm both fail to find a shortest path? Can
Bellman Ford detect all negative weight cycles in a graph? Apply Bellman Ford algorithm
on the following graph:
Q2) The longest-simple-cycle problem is the problem of determining a simple cycle (no
repeated vertices) of maximum length in a graph. Formulate a related decision problem,
and show that the decision problem is NP-complete.
Q3) Consider the weights and values of items listed below. Note that there is only one unit of
each item.
Number Weight (in Kgs) Value (in Rupees)
1 8 50
2 6 30
3 3 18
4 4 20
The task is to pick a subset of these items such that their total weight is not more than 11
and their total value is maximized. Moreover, no item may be split. The total value of items
picked by an optimal algorithm is V_opt. A greedy algorithm sorts the items by their
value/weight ratios in descending order and packs them greedily, starting from the first
item in the ordered list. The total value of items picked by the greedy algorithm is denoted
V_greedy. The value of (V_opt – V_greedy) =?
Q4) Consider the following characters along with their respective frequencies in a given
message
Character C U _ C O S C
Frequency 5 10 15 20 25 30 50
Using the Huffman coding algorithm, construct an optimal Huffman Tree.
Tasks:
a) Calculate the path length (depth in the tree) for each character
b) Find the total number of bits required to transmit the message “CU_COSC” using the
obtained Huffman Codes.