CIS 435 Homework 2 (Due: March 11, 2003) Solve ALL the problems. Collaboration is prohibited
8 points total
Problem 1. (2 points)
Solve Problem 7-3 (analysis of Stooge-Sort) from the textbook (page 161).
Problem 2. (2 points)
Solve Exercise 9-3.8 (O(log n) time computation of the median in a special case) from the textbook (page 193). Write the related algorithm in the pseudocode (informal programming language used in the textbook).
Hint:
Look at the relation between ”middle elements”.
Problem 3. (2 points) Assume we have the array
A = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21].
How will this array look after performing Build-Max-Heap(A) using the description of the function Build-Max-Heap(A) from the textbook.
Problem 4. (2 points) Assume we have the array
A = [1, 2, 12, 13, 3, 4, 14, 15, 5, 6, 16, 17, 7, 8, 18, 19, 9, 20, 10, 21, 11]
How will this array look after performing PARTITION(A, 1, 21), where PARTITION is the function from the textbook related to Quicksort (page 146). Assume the first position of A is 1.