Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using figures 6.4 and 7.1 of CLRS (pages 34 and 41, respectively, in the lecture slides for Chapter 7) as models, illustrate the operations of

Using figures 6.4 and 7.1 of CLRS (pages 34 and 41, respectively, in the lecture slides for Chapter 7) as models, illustrate the operations of Heapsort and the Partition procedure as given in lecture (pages 35 and 40, lecture slides for Chapter 7, respectively) on the array.. For Heapsort you may omit the steps of Build_Max_Heap and draw the heap right after Build_Max_Heap is executed on the input array as the 1st step of your solution. For Partition, assume that the last element of the array is selected

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

pj a287 1315164 (b) 2 87 13 3 64 CD 213 2 13 d) 2138713164 Figure 7.1 The operation of PARTITION on a sample array. Lightly shaded array elements are all in the first partition with values no greater than x.Heavily shaded elements are in the second partition with values greater than x. The unshaded elements have not yet been pat in one of the first two partitions, and the final white element is the pivot. (a) The initial array and variable settings. None of the elements have been placed in either of the first two partitions. (b) The value 2 s-swapped with itself and put in the partition of smaller values, (ed) The values 8 and 7 are added to the partition of larger values. (e) The values 1 and 8 are swapped, and the smaller partition grows. (n The values 3 and 8 are swapped, and the snaller partition grows. (g (h) The larger partition grows to include 5 and 6 and the loop terminates. (6) In lines 7-8, the pivot element is swapped so that it lies between the two partitions (D Ch) 14116 Figure 64 The operation of HEAPSORT. (a) The max-heap data structure just after it has been built by BUILD-MAX-HEAP. b)-(j) The max-heap just after each call of MAX-HEA PIFY n line 5. The value of i at that time is shown. Only lightly shaded nodes remain in the heap. (k) The resulting sorted array A HEAPSORT(A) 1 BUILD-MAx-HEAP(A) 2 fori <_ length downto do exchange a heap-size max-heapify partition p r x for j to r-1 returni if aljlx then i>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

define the term outplacement

Answered: 1 week ago

Question

describe the services that an outplacement consultancy may provide.

Answered: 1 week ago