CoursesTrees & Graphs

Tree BFS

Lessons
9
Exercises
56
Minutes
60
  1. 1

    Breadth-First Search

    Visit a tree in rings of distance from the root: a queue serves each level before its children, and one snapshot freezes a level.

    Multiple choiceTap
    6 exercises
    5 min
  2. 2

    Average of Levels

    Your first applied BFS: freeze each level, sum it, and divide by that level's width — not the tree's size.

    Complete codeDebugMultiple choiceTrace
    6 exercises
    6 min
  3. 3

    Level Order Traversal

    The canonical level-list builder — and the live queue.size() trap that smears nodes across the wrong levels.

    Complete codeMultiple choice
    6 exercises
    7 min
  4. 4

    Cousins in Binary Tree

    Cousins share a depth but not a parent — sweep one level at a time, watching for the pair AND the same-parent disqualifier.

    Complete codeDebugMultiple choiceTapTrace
    6 exercises
    6 min
  5. 5

    Binary Tree Right Side View

    The visible node of each level is the LAST one in its level snapshot — not necessarily a right child.

    Complete codeDebugMultiple choiceTrace
    6 exercises
    7 min
  6. 6

    Maximum Level Sum of a Binary Tree

    Sum each level as you sweep it, then argmax with a strictly-greater test — ties keep the SMALLEST level, and negatives mean wide levels can lose.

    Complete codeDebugMultiple choiceTrace
    6 exercises
    6 min
  7. 7

    Tree BFS CheckpointCheckpoint

    No new ideas — carry the BFS toolkit to problems you have not seen: early exit for the shallowest answer, per-level aggregates, and wiring next-right neighbors.

    Complete codeMultiple choiceTrace
    6 exercises
    7 min
  8. 8

    Tree BFS ReviewReview

    Mixed recap of the island: queue discipline, the level-size snapshot, last-in-level observations, when BFS beats DFS, and what level order really costs.

    DebugFill blankMultiple choiceTapTrace
    6 exercises
    6 min
  9. 9

    Boss: Zigzag Level OrderBoss

    Alternate the direction of every level without ever touching the queue — flip how each level's VALUES are recorded, never how the nodes are visited.

    Complete codeDebugCode orderMultiple choiceTrace
    8 exercises
    10 min
AlgoFox Pro

Trees & Graphs is part of AlgoFox Pro

You can read the whole course outline here. The exercises are in the app, along with your streak, your mistake review, and the progress that carries across your devices.

Pro starts with a 3 day free trial. The app store decides who is eligible for an introductory offer, and a lapsed subscription does not get another one.

Download AlgoFox on the App StoreGet AlgoFox on Google Play

Already subscribed in the app? Sign in with the same account and Pro works here too. Quick Play and Battle are free on the web, and so is the first course in every subject.