Description
1) Using Figure 7.1 as a model, illustrate the operation of PARTITION on the array
π΄[13,19,9,5,12,8,7,4,21,2,6,11]. [CLRS 7.1-1]
5 points
2) Assume that we have an array with length π containing integer numbers. Develop an efficient algorithm that
put all the negative numbers on the right side of the array and all the positive numbers on the left side. As an
example:
A = [5 , -2 , 3 , 4 , -1 , 0 , -2 , 2]
Answer = [5 , 3 , 4 , 0 , 2 , -2 , -1 , -2]
Order of the items in the answer are not important.
15 points
3) We can build a heap by repeatedly calling MAX-HEAP-INSERT to insert the ele- ments into the heap.
Consider the following variation on the BUILD-MAX-HEAP procedure:
a) Do the procedures π΅ππΌπΏπ·_ππ΄π_π»πΈπ΄π and π΅ππΌπΏπ·_ππ΄π_π»πΈπ΄πβ² always create the same heap when run
on the same input array? Prove that they do, or provide a counterexample.
b) Show that in the worst case, π΅ππΌπΏπ·_ππ΄π_π»πΈπ΄πβ² requires Ξ(π log π) time to build an n-element heap.
[CLRS 6-1]
15 points
4) Implement the Strassenβs method for matrix multiplication, to multiply two π Γ π matrices. Test your code
for three example: a 2 Γ 2 case, a 4 Γ 4 case, and an 8 Γ 8 case. Report your code as well as your test cases.
15 points