Like trees, heaps are typically implemented using either linked lists or linked nodes, or an array. Since we examined the linked node approach in Chapter 9, Trees: Nonlinear Structures, in this chapter, we'll examine an array implementation of a heap called a binary heap.
A binary heap is a tree structure where all levels of the tree are filled completely, with the possible exception of the last or deepest level. In the case of the deepest level the nodes are filled from left to right until the level is full. As you can see from the preceding figure, in an array-based implementation each parent node has two child nodes that are located at 2i + 1 and 2i + 2, where i is the index of the parent node and the first node of the collection is found at index 0.