iq.lab
Python starts when a code cell comes near or you run one

Module 8 · 5 lessons · about 8 hours 55 minutes

Recursion and trees

Recursion and the call stack, binary trees and their traversals, passing answers up the tree, level-by-level search, and binary search trees.

Lessons
0/5
Exercises
0/40
Code
0/6
Problems
0/24
Checkpoint
Not taken

Already comfortable with this? Take the checkpoint cold. If you pass, move on and come back only for what you missed.

  1. 1Recursion and the call stackA recursive function answers a question by asking itself the same question about something smaller, until it reaches a case it can answer outright. Watch the call stack grow and shrink, learn to trust the smaller call, and make slow recursion fast with a memo and with halving.1 h 40 min
  2. 2Binary treesA binary tree is a set of nodes in which each node points at up to two children. Visit every node in preorder, inorder or postorder with a short recursive function, visit it in preorder with a stack of your own, and answer most tree questions by building each node's answer from its children's answers.1 h 45 min
  3. 3Passing answers up the treeAt every node of a tree, ask two questions. What do I need from my children? What do I hand to my parent? Diameter, balanced trees, path sums and lowest common ancestors are four answers to that pair.1 h 50 min
  4. 4Level by levelA queue hands out a tree's nodes one level at a time, top to bottom and left to right. Count the queue before you take a level's first node and you know where that level ends, which answers level order, the right side view and the nearest leaf.1 h 45 min
  5. 5Binary search treesA binary search tree keeps one promise at every node, smaller values on the left and larger values on the right. That promise lets search and insert walk a single path, makes an inorder walk come out sorted, and turns three classic interview questions into short walks.1 h 55 min
  6. Checkpoint12 questions. Pass with 80% to finish the module.

Problems for this module

The lessons teach some of these step by step (each says which). The rest are practice: try each in its target time, and solved problems come back for spaced re-solves.

Next moduleHeaps and tries