Algorithms Test 1

Question 1. (5 points) In class, we discussed the worst-case analysis of "two-way" merge sort that split the array in two, merge sorted each half, and merged the resulting two halves together. The worst-case analysis of two-way merge sort leads to a recurrence of :


where n is the number of elements in the array.

What is the recurrence for the best-case analysis of the two-way merge sort ? As in the worst-case analysis, use the number of comparisons between two array elements as the basic operation.

Question 2. (5 points) Consider a "four-way" merge sort algorithm that splits the array into four "equal" parts, recursively merge sorts each part, and merges the resulting parts together. Write the worst-case recurrence relationship for this four-way merge sort algorithm.

W(n) =

Question 3. (10 points) Suppose that you have an algorithm that requires 100 seconds to run on a problem size of 1000. How long would you expect the algorithm to run on a problem size of 10,000? (If you don't have a calculator, just write an equation for the answer.)

b) If you buy a computer that is 10-times faster, how long would you expect the algorithm to run on a problem size of 1000?

Question 4. (20 points) Analyze the following algorithm to determine its theta () notation. For partial credit, give the best big-oh () notation, you can for the algorithm.

i = 1

while i < n do

for j := 1 to n do

for k := 1 to j do

<something that takes >

end for

end for

i = i * 2

end while

Question 5. (20 points) Solve the following recurrence relation to determine its theta notation. You may assume that n is a power of 2, i.e., n = 2k and log2 n = k.

Question 6. (10 points) Explain why the divide-and-conquer technique is often inappropriate for calculating recursively defined mathematical function like Fibonacci.

Question 7. (30 points) Write a divide-and-conquer algorithm (C, C++, Ada, Java like) to calculate the binomial coefficient using the recursive definition of

for 0 < k < n

1 for k = 0 or k = n