Algorithmsbinary heap

Binary Heap Shape and Indices

TT
Testlaa Team
May 14, 20261 min read

Parent at (i-1)//2, children at 2i+1, 2i+2 in array storage.

Try this in Python

def parent(i):
    return (i - 1) // 2

print(parent(5), parent(0))

Key takeaways

  • 0-based vs 1-based shifts formulas—stick to one.
  • Height is O(log n).
  • Complete tree property enables array packing.

Tags:

HeapsPythonStudents