PythonIntermediate~5h

Interview: Trees & Graphs

One skeleton, and the family it answers

Somebody who has memorised twenty tree and graph solutions has learned nothing transferable. This is the other thing: one recursive shape, one graph walk, and the handful of rules that turn them into any question you are actually asked — drilled on structures generated fresh, then written from memory and run.

Modules
6
Drills
11
Build steps
4
Time
~5h

Walk out able to

Name the skeleton an unfamiliar tree or graph question needs, write it from memory, and say exactly what the walk produces.

What you drill

01

One skeleton, many answers

Base case, recurse, combine — passed down or handed back.

02

Traversal order, exactly

Pre, in, post and level — produced, not recognised.

03

The visited set

What a graph walk needs, and the moment you mark.

04

Same walk, new question

Cycles, topological order, and a grid with walls.

The pitch

What you practise, and what you leave with

A tree walk, a breadth-first walk and a pipeline diagnosis, each written from an empty editor against input built to break a careless one.

You will practise

  • The skeleton, line by line, until you can type it
  • All four traversal orders, written out exactly
  • Graph walks under a stated neighbour rule
  • Cycles, orderings and grids off one loop

Afterwards you can

  • Write the tree skeleton without looking it up
  • Produce any traversal sequence exactly
  • Say where a visited set goes, and why
  • Order a dependency graph that would not

Modules

6 modules, 30 items

Lessons explain one idea. Drills repeat it until it sticks. Build steps make something that exists afterwards.

  1. 1

    The skeleton under every answer

    ~31 min

    Write the base-case, recurse, combine shape and say which line a question changes.

    • LessonWhy one skeleton, not twenty4 min
    • LessonThe shape every answer has9 min
    • LessonChoose the base case5 min
    • DrillSay what the recursion returns13 min
  2. 2

    Traversal order, exactly

    ~53 min

    Produce any of the four sequences, choose the one a job needs, and read one backwards.

    • LessonMove the visit, change the order7 min
    • LessonLevel-order needs a queue6 min
    • LessonSay the tie-break, always5 min
    • DrillWrite the sequence out12 min
    • DrillPick the order the job needs10 min
    • DrillRebuild it from two orders13 min
  3. 3

    Down the tree, or back up it

    ~32 min

    Decide whether a node needs its ancestors, its descendants, both, or neither.

    • LessonAsk which way it travels9 min
    • LessonDown is a parameter5 min
    • LessonUp is a return value6 min
    • DrillSay which way it travels12 min
  4. 4

    Graphs and the visited set

    ~45 min

    State a graph walk’s exact visit order, and price what the visited set is worth.

    • LessonThe set that makes it stop6 min
    • LessonMark it as it goes in7 min
    • LessonSay the neighbour order first6 min
    • DrillWalk it under the stated rule13 min
    • DrillPrice the visited set13 min
  5. 5

    Same walk, different question

    ~58 min

    Point one walk at a cycle check, a topological order and a grid with walls in it.

    • LessonTwo cycle checks, not one8 min
    • LessonOrder needs a rule to be one6 min
    • LessonThe graph nobody wrote down6 min
    • DrillSay if the cycle check fires13 min
    • DrillOrder it under the stated rule13 min
    • DrillWalk the grid12 min
  6. 6

    Write them cold

    ~1h

    Recall each skeleton line by line, then type three of them from memory and run them.

    • DrillFill in the missing line12 min
    • Build stepWrite the tree walk cold18 min
    • Build stepWrite the graph walk cold18 min
    • Build stepFind the dependency that hangs it11 min
    • Build stepOrder the repaired pipeline11 min

One skeleton. Then the family it answers.

The first item is free. ~5h of focused work, at your own pace.

Intermediate~5h6 modules