🌱SproutStack
👤 Guest

🌱 DSA (Beginner) · Essential Data Structures · cozy lesson

Trees: BFS & DFS

13 min · 1 min read · no scary math, promise

🤖
You’ve got this. Read a little, play a little — I’ll wait. No rush.
def max_depth(r):
    if not r: return 0
    return 1+max(max_depth(r.left), max_depth(r.right))

from collections import deque
def levels(r):
    q, out = deque([r]), []
    while q:
        out.append([n.v for n in q])
        for _ in range(len(q)):
            n=q.popleft()
            if n.left: q.append(n.left)
            if n.right: q.append(n.right)
    return out

Check your understanding

Correct answers earn XP (once each).

1. DFS order for depth?

2. BFS uses…

My notes (saved in this browser)

Select text above → Save selection, or write your own. AlgoMaster-style notebook, local-first for MVP.

No notes yet. Your highlights will live here.

Finished reading? Seal it with a tick ✅

The checkbox in the explorer turns green too — same progress.