Back to library

🌳Trees and Binary Search Trees

Stop confusing BFS with DFS, in-order with pre-order, and balanced with not-quite. Build the tree intuition that lets you draw any node-and-edge problem on a whiteboard and solve five classic interview questions without freezing.

Foundations14 drops~2-week path Β· 5–8 min/daytechnology

Phase 1Why Trees Beat Lists for Hierarchy

See why trees trade flat lists for fast hierarchies

4 drops
  1. A tree is a list that grew a hierarchy

    6 min

    A tree is a list that grew a hierarchy

  2. Binary just means at most two children

    6 min

    Binary just means at most two children

  3. A BST trades sortedness for log-time lookup

    7 min

    A BST trades sortedness for log-time lookup

  4. Balance is the difference between O(log n) and O(n)

    7 min

    Balance is the difference between O(log n) and O(n)

Phase 2Coding Insert, Delete, and the Three DFS Traversals

Code insert, delete, and the three DFS traversals

5 drops
  1. Insert is search that places when it falls off the edge

    7 min

    Insert is search that places when it falls off the edge

  2. In-order traversal of a BST gives you a sorted list

    7 min

    In-order traversal of a BST gives you a sorted list

  3. Pre-order serializes; post-order destroys safely

    7 min

    Pre-order serializes; post-order destroys safely

  4. Delete is three cases β€” and one of them is sneaky

    8 min

    Delete is three cases β€” and one of them is sneaky

  5. Level order trades the call stack for a queue

    8 min

    Level order trades the call stack for a queue

Phase 3BFS vs DFS β€” Choose by Problem Shape

Pick BFS, DFS, or balanced β€” by problem shape

4 drops
  1. The interviewer says 'level' and you reach for a queue

    7 min

    The interviewer says 'level' and you reach for a queue

  2. Validate a BST without leaking your assumptions

    7 min

    Validate a BST without leaking your assumptions

  3. The LCA problem changes shape between BST and binary tree

    8 min

    The LCA problem changes shape between BST and binary tree

  4. Why a self-balancing tree is the production answer

    8 min

    Why a self-balancing tree is the production answer

Phase 4Solve Five Classic Tree Interview Problems

Solve five classic tree interview problems by hand

1 drop
  1. Walk into the interview ready for five tree problems

    20 min

    Walk into the interview ready for five tree problems

Frequently asked questions

What's the difference between a tree and a binary search tree?
This is covered in the β€œTrees and Binary Search Trees” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
When should I use BFS instead of DFS on a tree?
This is covered in the β€œTrees and Binary Search Trees” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
Why does in-order traversal of a BST give sorted output?
This is covered in the β€œTrees and Binary Search Trees” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
What makes a binary search tree balanced or unbalanced?
This is covered in the β€œTrees and Binary Search Trees” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
How do I delete a node from a BST without breaking it?
This is covered in the β€œTrees and Binary Search Trees” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.