Trees

Concept shape

Core
Definition

A heap keeps the highest or lowest priority item at the top.

Step 1 / 5
Concept shape
Current lesson

Heaps and Priority Queues Lab

Trees Core

Heaps and Priority Queues

Welcome to the Heaps and Priority Queues concept lab. A heap keeps the highest or lowest priority item at the top. The must know points are: Peek is O(1). Push and pop are O(log n). Priority queues are usually implemented with heaps. The common operations are: peek O(1), push O(log n), pop O(log n). The complexity shape is Push/pop O(log n), peek O(1). Watch out for these pitfalls: Expecting the whole heap array to be sorted. Using a normal queue when priorities matter. Related algorithms include Heap Sort, Dijkstra Shortest Path.

Concept details

A heap keeps the highest or lowest priority item at the top.

Must know

  • Peek is O(1).
  • Push and pop are O(log n).
  • Priority queues are usually implemented with heaps.

Complexity

Push/pop O(log n), peek O(1)

Open deeper visual structure lesson
1.0x