IntermediateAbout 20 min

    Depth-First Search (DFS)

    Read the full article on Substack

    5 min read.

    Explore graphs by going deep! Unlike BFS, DFS dives into the graph structure. Essential for detecting cycles, topological sort, and maze solving.

    ABCDEF
    stack
    order

    Depth-first from A: go as deep as possible, then backtrack.

    1/20

    Check your understanding

    Answer from memory before you scroll back up. Pulling an idea out of your head is what makes it stay there.

    Go deep first

    Sequence

    Graph: A → B, C · B → D, E · C → F. Visiting neighbours alphabetically, order the nodes as DFS from A visits them.

    Tap a piece, then tap where it goes — or drag it. Tap the tray to take one back.

    1. 1Drop a step here
    2. 2Drop a step here
    3. 3Drop a step here
    4. 4Drop a step here
    5. 5Drop a step here
    6. 6Drop a step here
    6 pieces left to place

    Quiz

    20 questions
    Question 1 of 20
    Score: 0

    What data structure is implicitly used in recursive DFS?

    Done with this lesson?

    Sign in free to keep your progress, streak and quiz scores.

    Keep going