Professional Documents
Culture Documents
2017 Final Solutions
2017 Final Solutions
(a) False, then we could sort in O(n) time using an in-order traversal of the BST.
(b) True, see CLRS p.153 Build-Max-Heap.
(c) O(n)
(d) True.
(e) True, heapsort is not stable.
(f) A is in P since it’s poly-reducible to B. Nothing can be said of C.
(g) True.
(h) Θ(lg n).
(i) True.
(j) False. One only is guaranteed to be in an MST.
0 1 2 3 4 5 6 7 8 9 10
100 X 25 X 61 50 X 20 43
A(i) is the maximum sum-product when considering only the first i numbers.
(b) function MaxSumProduct(a)
1
A[0] ← 0
A[1] ← a[i]
for 2 ≤ i ≤ n do
A[i] ← max(A[i − 1] + a[i], A[i − 2] + a[i] × a[i − 1])
end for
return A[n]
end function
Both running time and space requirements are O(n).