kkkkk52

62 阅读1分钟

Exercise 10 Assume you have k sorted lists containing a total of n items. You want to merge them into 1 sorted list. Give a pseudo code or steps of your algorithm. Using that pseudo code comment on the complexity of the algorithm. Your algorithm should use a heap to solve the problem. Answer:

Exercise 9 (a) Similar to Figure 6.3, illustrate the operation of BUILD-MAX-HEAP function (from the textbook) on the following array A = <7, 5, 13, 8, 55, 17,2, 25, 10>. Answer: (b) Use the heap constructed in part a and similar to figure 6.4 illustrate the operation of HEAPSORT function (from the text book) on the heap from part a. Answer:

1, Write a pseudo code that calculates frequency of a number in given array. Use the loop invariant technique i.e initialization, main- tenance and termination steps and show that pseudo code calculates the frequency of a given number correctly