DSA Factory
All free lessons
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

  1. Search a BSTCompare with root and step left or right, discarding half the remaining nodes each time.8 min
  2. Minimum value in BSTWalk left until there are no more left children; the leftmost node is the minimum.7 min
  3. Insert into a BSTFollow the search path until you hit null, then attach the new node as a child.8 min
  4. Closest value in BSTTrack the closest node seen so far while navigating left or right toward the target.9 min

Stage 1Ordered walks

  1. 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
  2. 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
  3. 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
  4. 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