Heap

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.

Updated August 2, 2012

Definitions by TechTerms.com

The definition of Heap on this page is an original TechTerms.com definition. If you would like to reference this page or cite this definition, you can use the green citation links above.

The goal of TechTerms.com is to explain computer terminology in a way that is easy to understand. We strive for simplicity and accuracy with every definition we publish. If you have feedback about the Heap definition or would like to suggest a new technical term, please contact us.

Want to learn more tech terms? Subscribe to the daily or weekly newsletter and get featured terms and quizzes delivered to your inbox.

Sign up for the free TechTerms Newsletter

How often would you like to receive an email?

You can unsubscribe or change your frequency setting at any time using the links available in each email.

Questions? Please contact us.