FinalExam Handout
FinalExam Handout
Final exam will be a 2-hour long in-class exam on Thursday, May 11, 2023 at 7:30AM-9:30AM in
CS 220. You may have 6 questions to solve, depending on the size of the questions. This handout
presents a few review questions for the final examination.
Section 2 Recursion
1. Using substitution method, prove that the recurrence relation f (n) = 2f (n/2) + n results in
f (n) = O(n log n).
2. Solve T (n) = 2 T (n/3) + n2 using recursion trees, and verify the result using Master’s
theorem.
2. The problem is to compute the product of two n-bit input arrays A and B, where n is signif-
icantly larger than the register size in your processor (e.g. Consider the product of 256-bit
arrays over a 64-bit processor). In such a case, it is infeasible to run the traditional method
for finding the product of two arrays. How would you solve this problem?
1
Section 4 Comparison Sorting
1. Write the pseudocode for I NSERTION -S ORT and prove its correctness.
2. Given two sorted input arrays A and B, how can we merge them into a sorted array? Write
the pseudocode for your approach and prove its correctness.
3. Prove that the worst-case run time for H EAP -S ORT is Θ(n log n).
4. If we were to employ divide and conquer approach to design a comparison sort, demonstrate
various sorting algorithms when the pivot element q is always chosen to be
and write the pseudocode for the dynamic programming solution to 0-1 Knapsack problem.
2
Section 7 Greedy Algorithms
1. When can a greedy algorithm produce an optimal solution?
2. Demonstrate on the following example, how to find an optimal solution to the Fractional
Knapsack problem using a greedy algorithm?
2. Demonstrate Depth-first search (DFS) on a graph, such as the one shown in Figure 2.
3. What is the main difference between the implementation of BFS and DFS algorithms?
2. Demonstrate Prim’s algorithm on the graph, such as the one shown in Figure 3.
3. Explain why dynamic programming is not a good approach to find minimum spanning trees?
3
Figure 3: Minimum Spanning Trees
2. Demonstrate Dijkstra’s algorithm on the graph, such as the one shown in Figure 4.