If we represent a heap using array the 2nd half of the array will be represent the leaf nodes of the heap. But I can not understand for array of length n, all elements in range A[[n/2+1]....n] are heaps.

A clear explanation help me in understanding.

Thank you.

  • 1
    $\begingroup$ Hint: A heap, could be represented as a tree, right? if we remove the root of a tree, we still got a tree, (or a subtree if you want) . (spoiler: part of tree is still a tree, a tree is a heap, part of a heap is a heap) $\endgroup$
    – user206904
    Oct 20 '21 at 1:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.