0

Given an array [3, 1, 8, 5, 4, 7, 6], I want to show the result of the first two iterations of heap sort, plus the result of initial build-heap to make a max heap.

Here is what I have so far

Initial:        [3, 1, 8, 5, 4, 7, 6] 

After max-heap: [8, 5, 7, 1, 4, 3, 6]

After 1st iter: [7, 5, 6, 1, 4, 3, 8]

After 2nd iter: [6, 4, 5, 1, 3, 7, 8]

Is my answer correct?

I am mostly concerned with the second iteration, as my professor said I got the second iteration wrong, but I cannot figure out where I went wrong with it.

Omar N
  • 1,720
  • 2
  • 21
  • 33

1 Answers1

0

I found the issue. I was not percolating up correctly on the 2nd iteration. The second iteration should look like this:

After 2nd iter: [6, 5, 3, 1, 4, 7, 8]

Omar N
  • 1,720
  • 2
  • 21
  • 33