Skip to content

Trees

A tree is a family tree: one root, each node has children, no loops. Nearly every tree problem is solved by trusting recursion — "solve the left subtree, solve the right subtree, combine" — or by visiting level by level with a queue.

After this topic: You can write DFS and BFS from memory, decide what each recursive call returns, and combine child answers.

Do these first: Binary Search, Linked List

0 of 15 solved0%

Step 0 · New to this idea? Warm up first

Recursion Basics

Solve a problem with a smaller copy of itself: base case, call stack and why recursion can repeat work.

Step 1 · Read the lesson

Trees: BFS / DFS

Recurse on subtrees, or sweep level by level with a queue.

Step 2 · Solve the problems in order

Try each one for about 20 minutes first. Problems with a Run code tab are checked right here. If you are stuck, open Nudge, think again, then Idea. Go skeleton only gives the function shape, and Reference solution is for comparing after you have tried. Tick the box when you could solve it again without help.

Step 3 · What this unlocks