Dsa End Term
Dsa End Term
1. (5 points) Use Kruskal’s algorithm on the given graph to find the minimum spanning
tree. List the edges in the order you included them during the run of the algorithm.
(5 points)
2. (5 points) Find shortest path between s and t using Dijkstra’s algorithm. (5 points)
3. (5 points) Given the following Fibonacci heap, where nodes with an asterisk are
“marked”, perform extractMin() on it and then decreaseKey() on the node whose
key is currently 66, bringing it down to 4. Redraw the changed heap as you go along.
You need only draw any significant intermediate states of the heap, adding any
necessary explanations so that a reader can follow what you are doing and why. (5 points)
4. (5 points) Given an unlimited supply of coins of given denominations, our goal is
to find the minimum number of coins required to get the desired change.
For example, consider coins of denomination given in the set S = {1, 3, 5, 7}. If
the desired change is 15, the minimum number of coins required is 3. This can be
obtained as (7 + 7 + 1) or (5 + 5 + 5) or (3 + 5 + 7). On the other hand, if
the desired change is 18, the minimum number of coins required is 4, which can be
achieved as (7 + 7 + 3 + 1) or (5 + 5 + 5 + 3) or (7 + 5 + 5 + 1).
Describe a dynamic programming algorithm to solve this problem, given an array S
of denominations and a target value T to achieve. The algorithm must output the
minimum number of coins required.
(5 points)
i f ( s t a r t −>next != NULL )
fun ( s t a r t −>next−>next ) ;
p r i n t f (”%d ” , s t a r t −>data ) ;
}
Page 2
6. (5 points) In the given Red-Black tree, insert a new element with value 64. Explain
the process of insertion. The current values in the tree are (level by level, left to
right, starting from root) 30, 15, 70, 10, 20, 60, 85, 5, 50, 65, 80, 90, 63, 67. (5 points)
7. A 3-ary max heap is like a binary max heap, but instead of 2 children, nodes have 3
children. A 3-ary heap can be represented by an array as follows: The root is stored
in the first location, a[0], nodes in the next level, from left to right, is stored from
a[1] to a[3]. The nodes from the second level of the tree from left to right are stored
from a[4] location onward. An item x can be inserted into a 3-ary heap containing n
items by placing x in the location a[n] and pushing it up the tree to satisfy the heap
property. Which one of the following is a valid sequence of elements in an array
representing 3-ary max heap?
(A very brief reasoning, e.g. one or two sentences is required for each part).
(a) 1, 3, 5, 6, 8, 9 (1)
(b) 9, 6, 3, 1, 8, 5 (1)
(c) 9, 3, 6, 8, 5, 1 (1)
(d) 9, 5, 6, 8, 3, 1 (1)
(e) 9, 8, 6, 5, 3, 1 (1)
8. State true or false with a very brief reasoning (e.g. one or two sentence or a diagram).
(a) A decision problem is easier to solve than a computational problem. (1)
(b) A non-deterministic finite automata has equal power as a deterministic finite
automata. (1)
(c) Let X be a problem which is in NP. Then there is no polynomial time algorithm
for X. (1)
(d) Let X be a problem which is in NP. If X is in NP-Hard then X is in NP-
Complete. (1)
(e) The 3SAT problem is in NP-Hard class. (1)
Page 3