A heap is a data structure made up of "nodes" that contain values. A typical heap has a root node at the top, which may have two or more child nodes directly below it. Each node can have two or more child nodes, which means the heap becomes wider with each child node. When displayed visually, a heap looks like an upside down tree and the general shape is a heap.
While each node in a heap may have two or more child nodes (also called "children"), most heaps limit each node to two children. These types of heaps are also called binary heaps and may be used for storing sorted data. For example, a "binary max heap" stores the highest value in the root node. The second and third highest values are stored in the child nodes of the root node. Throughout the tree, each node has a greater value than either of its child nodes. A "binary min heap" is the opposite, where the root node stores the lowest value and each node has a lower value than its children.
In computer science, heaps are often drawn as simple diagrams. However, actually storing data in a heap is more complex. In order to create a heap, programmers must write individual algorithms for inserting and deleting data. The values inserted into a heap are typically stored in an array, which can be referenced by a program. Since the data in a heap is already sorted, it provides an efficient means of searching for specific values.
NOTE: "The heap" is also a programming term that may be used to describe dynamically allocated memory. This block of memory can be accessed by active applications. Since memory in the heap is allocated dynamically, it may grow or shrink depending on how much memory is being used.