# Learn Heaps

Learn the data structure of heaps using Python. A heap is a specialized type of tree with many applications.

Start## Key Concepts

Review core concepts you need to learn to master this subject

Heap Implementation

Heap Implementation

Heaps are typically implemented with a data structure such as an array or Python list. These sequential structures allow access to elements in a particular order which is key to efficient use of heaps. Although binary trees are helpful for understanding the relationships between nodes of a heap, implementation using a tree is less efficient for storage and retrieval of elements.

Heaps: Conceptual

Lesson 1 of 2

- 1Heaps are used to maintain a maximum or minimum value in a dataset. Our examples use numbers since this is a straight-forward value, but heaps have many practical applications. Imagine you have a…
- 2We can picture min-heaps as binary trees, where each node has
**at most**two children. As we add elements to the heap, they’re added from left to right until we’ve filled the entire level. At th… - 3Sometimes you will add an element to the heap that violates the heap’s essential properties. We’re adding 3 as a left child of 11, which violates the min-heap property that children must be larg…
- 4Maintaining a minimum value is no good if we can never retrieve it, so let’s explore how to remove the root node. In the diagram, you can see removing the top node itself would be messy: there wo…

## How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory