Saturday, December 28, 2024
Google search engine
HomeData Modelling & AIArray Representation Of Binary Heap

Array Representation Of Binary Heap

A Binary Heap is a Complete Binary Tree. A binary heap is typically represented as array. The representation is done as:

  • The root element will be at Arr[0].
  • Below table shows indexes of other nodes for the ith node, i.e., Arr[i]:
    Arr[(i-1)/2] Returns the parent node
    Arr[(2*i)+1] Returns the left child node
    Arr[(2*i)+2] Returns the right child node
  • The traversal method use to achieve Array representation is Level Order
    binary-heap-array-mapping
    Binary Heap satisfies the Ordering Property.
    The Ordering can be of two types:
    1. Min Heap Property: The value of each node is greater than or equal to the value of its parent, with the minimum value at the root.

    Examples:
    min-heap

    2. Max Heap Property: The value of each node is less than or
    equal to the value of its parent, with the maximum value at the root.

    Examples:
    max-heap

    For the implementation of the basic heap operations follow the link :https://www.geeksforgeeks.org/binary-heap/

    This article is contributed by Saksham Raj Seth. If you like neveropen and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the neveropen main page and help other Geeks.

    Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

    Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
    Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

RELATED ARTICLES

Most Popular

Recent Comments