Question & Answer: Follow the textbook convention and illustrate the operation of HEAPSORT on the array A = Show all intermediate steps including how the heap is creat…..

3. Follow the textbook convention and illustrate the operation of HEAPSORT on the array A <5, 7, 2, 3, 8, 9>. Show all intermediate steps including how the heap is created and transformed. [10 points]

Follow the textbook convention and illustrate the operation of HEAPSORT on the array A = Show all intermediate steps including how the heap is created and transformed.

Expert Answer

 

The steps are as follows:

The data is 5,7,2,3,8,9

We will go for min heap. The node will be lower than the nodes.

The tree created will be

Step 1

5

7        2

3     8   9

In this step our array is 5,7,2,3,8,9

Step 2. We will apply heapify to (6/2-1)= 2 index of the array

5

7       2

3     8 9

We don’t have to do any thing as 2 is ok.
array is 5,7,2,3,8,9

Step 3 . We will apply heapify to array index = 1, i.e 7

5

3         2

7       8   9

We need to swap 3 and 7.

The array becomes 5,3,2,7,8,9

Step 4 We will apply heapify to array index 0 i.e 5

5

3        2

7      8 9

We need to swap 5 and 2.
Our array becomes 2,3,5,7,8,9

Step 5. We need to check the tree now.

2

3        5

7        8 9

Every thing is ok. So we have our sorted array as 2,3,5,7,8,9

Still stressed from student homework?
Get quality assistance from academic writers!