CS 415 Algorithm Analysis Spring 2006 Practice Problems for the final examination 1) An algorithm solves a problem of size n (in the worst-case) in 20 n2 steps, while another algorithm takes n3 steps in the worst-case for the same problem. What is the smallest value of n for which the former algorithm would outperform the latter? 2) Use iterative substitution to solve the recurrence equation T(n) = 2 T(n – 1) + 1, with the initial condition T(1) = 1. 3) In practical implementations of recursive divide and conquer algorithms, the splitting stops when the size of the sub-problem reaches a small enough value at which point a simple straight-forward algorithm is used to solve it. Suppose we use this idea to implement Merge-sorting and switch to Insertion-sorting when the size of the sub-problem is 16. Write a recurrence formula for the worst-case number of comparisons performed by the resulting algorithm. (Use the fact that the worst-case number of key comparisons performed by Insertion-sorting is n(n – 1)/2 for n keys.) Also assume that the number of input keys is a power of 2. 4) Describe an algorithm that takes as input a heap A, and an index j size, and removes the key A[j] from the heap. Your algorithm should be time complexity O(log n) where n is the size of the heap. Use Heapify-up and Heapify-Down, with minimal additional code. 5) Consider the following knapsack problem: Object Weight Profit 1 2 3 4 7 4 8 6 21 11 23 15 Volume of the knapsack is 20. (a) Let T[j, k] denote the optimal solution of the problem with the first j objects, where the profit is k. What values does T[4, 15] depend on? What values does T[3, 10] depend on? (b) If we are allowed to choose the same object more than once, what is the optimum solution to the above problem? 6) Consider a version of the knapsack problem in which each object has a weight and a profit, and a specified knapsack capacity. Each object can be taken 0 or 1 time. Will any of the following ((greedy) algorithms always produce an optimal solution? In each case, an order of the objects is specified. The algorithm includes the objects one at a time in that order and skips over the objects that will cause the weight of the knapsack to exceed the capacity. Prove or give a counter-example: (a) increasing order of weight. (b) decreasing order of profit (c) decreasing order of profit to weight ratio 7) You bring a t-foot log of wood to your favorite sawmill. You want it cut in k specific places: t1 , t 2 ,..., t k feet from the left end. The sawmill charges x dollars to cut an x-foot log any place you want. Give a dynamic programming based algorithm that determines the order in which they should cut in order to minimize the cost. Estimate the time complexity of your algorithm. (It should be a polynomial in k.) 8) Exercise 3.12, page 112. 9) Exercise 4.22, page 200. 10) Exercise 5.2, page 246. 11) Exercise 7.4, page 416. 12) Exercise 7.5, page 416.