2014.08.22
Jingchao Hu
Caigen100 Corp.
The candidates usually need a lot of tips and advices before they can actually come to this conclusion
1 The first n/2 elements go on the bottom row of the heap. h=0, so heapify is not needed.
2 The next n/4 elements go on the row 1 up from the bottom. h=1, heapify filters 1 level down.
i The next n/2^i elements go in row i up from the bottom. h=i, heapify filters i levels down.
log(n) The last 1 element goes in row log(n) up from the bottom. h=log(n), heapify filters log(n) levels down.
O(n*(1/4+2/8+3/16+..i/2^(i+1)..+log(n)/n))
= O(n)