Sorting Heaps

1
A = { 6 , 2 , 1 , 0 }

Consider the max heap above. After the end of the first iteration of the loop that takes place in executing Heap Sort , the array for of the max heap will take the form of :

1
A = {a , b , c , d }

Where a a , b b , c c and d d are positive integers. Input 1000 a + 100 b + 10 c + d 1000a+100b+10c+d as the answer.


The answer is 2016.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Hasmik Garyaka
Oct 14, 2017

First we swap first and last elements. A={0,2,1,6}. Then execute heapify procedure for first 3 elements. And get {2,0,1,6} ```Pascal Heapify(A, i)

left ← 2i

right ← 2i+1

largest ← i

if left ≤ A.heap_size и A[left] > A[largest]

then largest ← left

if right ≤ A.heap_size и A[right] > A[largest]

then largest ← right

if largest ≠ i then swap A[i] ↔ A[largest] Heapify(A, largest) ```

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...