CISC 320 Algorithms, Fall 2007
Homework set #4, due Fri, Nov. 2.
-
Exercise 4.5
-
Show how to reduce exercise problem 4.6 to problem 4.7. In other words, assume you have a function Goog(p, f) which takes arrays p and f of length n each, where pi and fi have the meaning described in 4.7 concerning the i-th job. Goog returns a schedule for the jobs ( a list of the job numbers in the appropriate order). Use Goog to help solve problem 4.6, where the input is three arrays of swim, bike, and run times respectively.
- Given two sorted arrays A and B of sizes m and n respectively, using O(log(m)+log(n)) comparisons of array entries, determine the median value in the arrays. You may assume the m+n values are distinct. The median is the value that would be in position (m + n)/2, rounded up, if the m + n entries were put together in a single array and sorted (1-base indexing). For instance with m = 3 and n = 6, the median is the 5th in order of the 9 elements. With m = 3 and n = 5, the median would be the 4th of the 8 values.
Write pseudocode and explain why your algorithm correctly finds the median and uses only O(log(mn)) comparisons. Note: The case when m = n is exercise 5.1 which we solved in class.
- Exercise 5.4, but simplify the formula to Fj =
q1qj +
q2qj +
q3qj +
...
qj-1qj -
qj+1qj -
qj+2qj -
...
qnqj.
-
Extra credit: Implement Goog (see first hw problem above), i.e. solve exercise 4.7.