AlgoViz
HomeBinary Search Trees

Binary Search Trees

Ordered trees — left is smaller, right is larger, search in O(h).

0/ 21 understood · 0%
Walkthroughs
11
Problems
21
Start here
21 shown
  1. OverviewThe BST ordering propertyEasy
  2. Insert into a BSTWalk down, hang a new leafMedium
  3. Validate BSTEvery node within a (min, max) rangeMedium
  4. Kth Smallest in a BSTInorder visits keys in sorted orderMedium
  5. Lowest Common Ancestor in a BSTThe split point of the two valuesMedium
  6. Practice problems
  7. Introduction to BSTLeft is smaller, right is bigger — everywhereEasy
  8. Search in a Binary Search TreeCompare and descendEasy
  9. Find Min/Max in BSTWalk hard left, or hard rightEasy
  10. Floor and Ceil in a BSTRecord the candidate as you descendEasy
  11. Floor in a Binary Search TreeLargest value not above the keyEasy
  12. Insert a given node in BSTDescend to the empty spot and attachMedium
  13. Delete a node in BSTThree cases; two children is the interesting oneMedium
  14. Kth Smallest and Largest element in BSTIn-order traversal, countingMedium
  15. Check if a tree is a BST or notCarry a valid range down, not just the parentMedium
  16. LCA in BSTDescend until the values splitMedium
  17. Construct a BST from a preorder traversalBuild with an upper boundMedium
  18. Inorder Successor/Predecessor in BSTRemember the last turn you tookMedium
  19. Merge 2 BST'sTwo in-order traversals, then mergeHard
  20. Two Sum In BSTTwo iterators, walking inwardsHard
  21. Correct BST with two nodes swappedIn-order finds exactly the two anomaliesHard
  22. Largest BST in Binary TreeReturn (min, max, size, isBST) from each subtreeHard