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
2. Pattern 1 · Core operations
3. Pattern 2 · Using the BST property
4. Pattern 3 · In-order is sorted
5. Pattern 4 · Building BSTs
6. Pattern 5 · Successors, serialization and hard problems
Related courses
- Binary TreeHierarchical structures for representing nested relationships and enabling fast search.5 lessons · 16 problems
- SearchingBinary search and its many disguises across sorted and rotated structures.5 lessons · 22 problems
- Recursion & BacktrackingBreaking problems into smaller versions of themselves, and undoing choices that don't work out.5 lessons · 20 problems
