Trees

Problem shape

Intermediate
8
3
10
1
6
9
14
Core idea

Maintain the heap property by bubbling values up or down.

Step 1 / 5
Problem shape
Current lesson

Heap Push and Pop Lab

Trees Intermediate

Heap Push and Pop

Welcome to the Heap Push and Pop algorithm lab. Maintain the heap property by bubbling values up or down. Use it when: Use for priority queues, scheduling, k-largest, and graph algorithms. The time complexity is O(log n), and the space complexity is O(1). The pseudocode is: push(value) append value bubble up while parent is larger pop() replace root with last bubble down As you practice, track the state that changes and the condition that makes the algorithm stop.

Time

O(log n)

Space

O(1)

Pseudocode

push(value)
  append value
  bubble up while parent is larger
pop()
  replace root with last
  bubble down
Open deeper structure lesson
1.0x