Skip to main content
PProfileMatch
← Path

Data Structures · Trees and Heaps in Python: Traversals and heapq in Practice

0 XP
  1. 1 current stop: learning
  2. 2 upcoming
  3. 3 upcoming
  4. 4 upcoming
  5. 5 upcoming

Finish after stop 5

Stop 1 of 5 · Forest trail map

Trick to keep in mind+3 XP

Levels use a queue; depth uses a stack.

Breadth-first order visits all nodes at one depth before any deeper node. To do that, children must wait behind the nodes already waiting, which is first in, first out. Depth-first follows one branch to the bottom, which suits a stack or plain recursion. Pick the container by the order you want.

Read it once, then a question tests whether the trick stuck.