This document outlines 10 questions for an algorithms assignment. The questions cover topics like analyzing algorithm running times, finding minimum/maximum elements, linear-time selection algorithms, modifying quicksort, analyzing matrix multiplication algorithms, binary search trees, lower bounds for comparison-based sorting, and range querying over a set of integers. The assignment is due on October 24th at 5:00 PM.
This document outlines 10 questions for an algorithms assignment. The questions cover topics like analyzing algorithm running times, finding minimum/maximum elements, linear-time selection algorithms, modifying quicksort, analyzing matrix multiplication algorithms, binary search trees, lower bounds for comparison-based sorting, and range querying over a set of integers. The assignment is due on October 24th at 5:00 PM.
Due: Oct. 24, Thursday, 5:00 PM. . 1. (10) The running time of an algorithm A is described by the recurrence t(n) = 7t(n/2) + n 2 . A competing algorithm A has a running time of T(n) = aT(n/4) + n 2 . What is the largest integer value for a such that A is asymptotically faster than A? 2. (5) In class, we showed an algorithm that nds the smallest and the largest of n numbers using 3n/2 2 comparisons when n is even. Show how to nd these two elements using 3n/2 3/2 comparisons when n is odd. 3. (10) Given n arbitrary numbers, how can you use our linear-time selection algorithm to nd the k smallest numbers in O(n) time? For example, if we have 4, 3, 3, 9, 10, 2, 3, then the two smallest numbers are 2 and 3 (or 3 and 2. Your answer does not have to be sorted). Similarly, the four smallest numbers are 3, 3, 2, 3. 4. (10) Will we still have a linear selection algorithm if elements are grouped into groups of 7? Prove your answer. What about 3? 5. (5) Quicksort has a worst case running time of O(n 2 ) and a best and average case running time O(nlog n). How can you modify the quicksort so that its worst case running time is O(nlog n)? 6. (10) Suppose we exchange elements A[i] and A[i +k] in an array, which were originally out of order. Find out how many inversions can be removed. You need to give a lower bound and an upper bound and show why. 7. (20) (a) What is the largest k such that if you can multiply 3 3 matrices using k multiplica- tions, then you can multiply n n matrices in time o(n log 7 )? What would the running time of this algorithm be? You can assume that n is a power of 3. (b) V. Pan has discovered a way of multiplying 68 68 matrices using 132,464 multiplications, a way of multiplying 70 70 matrices using 143,640 multiplications, and a way of multiplying 72 72 matrices using 155,424 multiplications. Which method yields the best asymptotic running time when used in a divide-and-conquer matrix-multiplication algorithm? How does it compare to Strassens algorithm? 8. (10) Consider the following sorting algorithm: I. Insert the given input A[1], A[2], ..., A[n] into a binary search tree T in the given order, starting from an empty tree; II. Do an inorder traversal of T to output the elements in non-decreasing order. (a) What is the worst case time for the algorithm? (b) What is the best case time for the algorithm? 9. (10) Show that the lower bound for any comparison-based algorithm for constructing a binary search tree from an arbitrary list of n elements is (nlog n). 10. (10) Describe an algorithm that, given n integers in the range 0 to k, preprocesses its input and then answers any query about how many of the n integers fall into a range [a..b] in O(1) times. Your algorithm should use O(n+k) preprocessing time. For examples, let the input be 1, 3, 5, 2, 1, 5, 0, 7, 5, 7, 3, 2, 4, 0. If the query is a = 4 and b = 6, the answer (in constant time) is 4. Similarly, if the query is a = 6 and b = 6, then the answer is (in constant time) 0. 1