Compile Ready
DSA
DSA/Trees & BST

Trees & BST

This is a premium interview-preparation course on the data structure that shows up in more interviews than any other: the **binary tree**, and its ordered cousin the **binary search tree**. Trees reward a single mental shift — stop thinking about the whole structure and start thinking about one node, its left subtree, and its right subtree. Almost every problem here is solved by asking what a node needs from its children (a bottom-up **depth-first** pass) or what it needs to pass down (a top-down pass), or by sweeping the tree one level at a time (**breadth-first**). You will start with the vocabulary — nodes, height, depth, balance, and the four traversal orders — then work through curated problems grouped by the patterns interviewers test: DFS traversals, BFS level-order, the BST ordering invariant, recursive subtree aggregation, rebuilding a tree from its traversals, and advanced problems that combine these ideas. Every lesson visualises the recursion or the level sweep on a concrete tree before showing a clean Java 17 solution.

30

Curated lessons

7

Learning modules

9h 3m

Est. study time

12

Target companies

What you'll learn

  • Choose DFS (preorder, inorder, postorder) or BFS level-order based on what each node needs.
  • Turn a recursive definition into code: base case, recurse on children, combine results.
  • Exploit the BST ordering invariant to search, insert, delete, and validate in O(h).
  • Rebuild trees from traversal orders and serialize them for transport.

Your progress

0%

0 / 30

problems completed

30 available now · keep going!

Mark lessons complete as you work through them. Progress is saved on this device and syncs to your account when you sign in.

Learning roadmap

Work top to bottom — each module builds on the last.

  1. 1

    Tree Fundamentals

    One node, a left subtree, and a right subtree

    The vocabulary every tree problem assumes: binary trees, the BST ordering invariant, height vs depth, balance, and the four traversal orders.

    6/6 problems46m
  2. 2

    DFS Traversals

    Recurse left, visit, recurse right (reorder as needed)

    Depth-first order in code: inorder, preorder, and postorder, plus the postorder combine step that computes a subtree's height.

    4/4 problems1h 3m
  3. 3

    BFS Pattern

    Queue holds one level; process it, enqueue the next

    Sweep the tree one level at a time with a queue: level order, zigzag, the rightmost node per level, and per-level aggregates.

    4/4 problems1h 3m
  4. 4

    BST Pattern

    Compare with the node, then go left or right

    Use the left-smaller / right-larger invariant to validate, search, insert, delete, and find a lowest common ancestor in O(h).

    5/5 problems1h 43m
  5. 5

    Recursive Tree Problems

    Return one value up; track a global best on the side

    Aggregate information from subtrees: diameter, balance, root-to-leaf path sums, and the maximum path sum that bends through a node.

    4/4 problems1h 21m
  6. 6

    Tree Construction

    Preorder/postorder picks the root; inorder splits the sides

    Rebuild a tree from its traversals and turn a tree into a string and back — the interview test of whether you truly understand traversal order.

    3/3 problems1h 25m
  7. 7

    Advanced Trees

    Compose DFS, BST order, and subtree DP

    Problems that combine the patterns: lowest common ancestor of any binary tree, order statistics on a BST, repairing a broken BST, and tree DP.

    4/4 problems1h 42m

Modules

7 themed modules from fundamentals to advanced.

Full curriculum

24 problems and 6 concept lessons in learning order.

Techniques you'll master

AggregationAncestorBFSBSTBalanced TreeBinary Search TreeBinary TreeDFSDeletionDepthDepth-First SearchDequeDesignDivide and ConquerDynamic ProgrammingFoundationsHard CombineHash TableHeightInorderInorder TraversalInsertionIterationLevel OrderLowest Common AncestorPostorderPreorderQueueRecoveryRecursionRoot-to-LeafSearchStackStringSubtree AggregationTraversalTree