Esc
  • Loading…
↑ ↓ to moveEnter to openEsc to close

Binary Search Tree

Learn the one rule that makes a binary tree searchable — smaller on the left, bigger on the right — how to search, insert, delete and walk it, and what balance has to do with speed. Then solve the BST questions interviews ask most.

  • 5 Lessons
  • 20 Problems
  • 52 Illustrations

What you will learn

  • What a binary search tree is: the ordering rule, and why it lets every comparison skip half the tree
  • Every core operation, recursively and iteratively: search, insert, find min and max, and delete with its three cases
  • Every way to walk a BST — in-order, pre-order, post-order and level order — and why in-order comes out sorted
  • Height, balance and memory: when a BST is O(log n), when it decays to O(n), and how balanced trees fix it
  • 5 patterns: core operations, using the BST property, in-order is sorted, building BSTs, and successors and serialization
  • The binary search tree interview questions asked most, from Search in a BST to Maximum Sum BST

Why this course

A binary search tree is a binary tree with one extra rule: everything in a node's left subtree is smaller than it, and everything in its right subtree is bigger. That rule turns every comparison into a decision to throw half the remaining tree away — the same idea as binary search, but on a structure you can also insert into and delete from.

The short introduction covers every way to work with a BST: searching and inserting (recursively and with a loop), deleting a node in each of its three cases, the four traversals and why in-order is sorted, and how height, balance and memory decide whether it's fast — each with a drawing and a simulator.

Then come 5 patterns, from easiest to hardest, each taught through the interview questions that use it, with code in four languages, the time and space of every approach and a simulator that shows the tree step by step.

Requirements

  • The Binary Tree course, or comfort with tree nodes, recursion over a tree and traversals
  • Binary search helps: a BST is binary search turned into a tree

Course Contents