Level 3 · Structures
Free Binary search trees lessons
8 lessons, about 86 minutes in all. Each teaches one idea with a visual, then gives you one problem built for it. Read the lessons here, then create a free account to solve the problems and keep your progress.
Stage 0Search and insert
- Search a BSTCompare with root and step left or right, discarding half the remaining nodes each time.8 min
- Minimum value in BSTWalk left until there are no more left children; the leftmost node is the minimum.7 min
- Insert into a BSTFollow the search path until you hit null, then attach the new node as a child.8 min
- Closest value in BSTTrack the closest node seen so far while navigating left or right toward the target.9 min
Stage 1Ordered walks
- Two values that add upDecide whether two different nodes of a search tree add up to a target, by reading the values in sorted order with an inorder walk and closing in from both ends.14 min
- The next value upFind the smallest value in a search tree that is larger than a given value, by walking down once and remembering the last node where you turned left.12 min
- Cut a tree down to a rangeRemove every node whose value lies outside a given range from a search tree, keeping the others in place, by discarding whole sides when a node is out of range.14 min
- Add everything that is biggerReplace each value in a search tree by itself plus the sum of all values greater than it, by walking the tree from the largest value down while keeping a running total.14 min
There’s more after this
These are the opening stages of Binary search trees. The full path climbs on to harder problems and a mastery test. Create a free account and we’ll keep your place.
Start the full path free