Constructing a Binary Heap

A binary heap can  be constructed in O ( n ) time

  1. Create an array and store the n elements in arbitrary order


  2. "Heapify" the array

    start at vertex i = |_ n / 2_|, the left most vertex in the the
    next to last level
    for each vertex from i up to the root, shift down



Example

    Construct a binary heap from the values {18, 2, 13, 10, 15, 3, 7, 16, 8}




Tuesday, 11-Apr-2000 15:33:48 EDT

Sorry! We could not find what you were looking for

Try going back to the main page here

 
4
4
0
0
0
0

Sorry! We could not find what you were looking for

Try going back to the main page here

 
4
4
0
0
0
0