This assignment covers Chapters 6 (Heaps), 7 (Quicksort), and 9 (Medians and Order Statistics) of the text [100 marks total]. Submit electronically, before midnight on Friday, 10/09/2015 using the submission link on Blackboard for Assignment #2, a file named yourFirstName-yourLastName.pdf containing your solution to this assignment (a .doc or .docx file is also acceptable, but .pdf is preferred).
1. Heaps. [10 marks total]
(a) What are the minimum and maximum number of elements in a heap of height h? [2 marks] (b) Show that an n-element heap has height blognc. [2 marks] (c) Show that in any subtree of a max-heap, the root of the subtree contains the largest value occurring anywhere in that subtree. [4 marks] (d) Is the sequence h23,17,14,6,13,10,1,5,7,12i a max-heap? Why or why not? [2 marks] 2. Heaps. [10 marks total] (a) Illustrate the operation of Max-Heapify(A,3) on the array A = h27,17,3,16,13,10,1,5,7,12,4,8,9,10i. [2 marks] (b) Illustrate the operation of Build-Max-Heap(A) on the array A = h5,3,17,10,84,19,6,22,9i. [3 marks] (c) You are given a list of numbers for which you need to construct a min-heap. How would you use an algorithm for constructing a max-heap to construct a min-heap? [5 marks]
3. Heapsort. [10 marks] Argue the correctness of Heapsort using the following loop invariant.
At the start of each iteration of the for loop, the subarray A[1…i] is a max-heap containing the i smallest elements of A[1…n], and the subarray A[i+1…n] contains the n−i largest elements of A[1…n].
4. Quicksort. [20 marks total] The Quicksort algorithm contains two recursive calls to itself. After Quicksort calls Partition, it recursively sorts the left sugary and then it recursively sorts the right subarray. The second recursive call in Quicksort is not really necessary; we can avoid it by using an iterative control structure. This technique, called tail recursion, is provided automatically by good compilers. Consider the following version of Quicksort, which simulates tail recursion:

Are you looking for a similar paper or any other quality academic essay? Then look no further. Our research paper writing service is what you require. Our team of experienced writers is on standby to deliver to you an original paper as per your specified instructions with zero plagiarism guaranteed. This is the perfect way you can prepare your own unique academic paper and score the grades you deserve.
Use the order calculator below and get started! Contact our live support team for any assistance or inquiry.
[order_calculator]