Module 5 · Heaps · Heap Tree Implementation

Heap tree as an array

A heap is a complete binary tree, but the Heap class stores no nodes or pointers, just an array. Number the nodes level by level, left to right, and node number i goes in arr[i]. The dashed arrows show where each node lands.

From the index alone, three formulas find a node's family (Java's integer division drops the fraction):

A child index of currSize or more doesn't exist (childExists is false), and the root, index 0, has no parent. Click any node or cell to see its parent and children.

Chapter