Skip to content

Latest commit

 

History

History
25 lines (17 loc) · 909 Bytes

bst.md

File metadata and controls

25 lines (17 loc) · 909 Bytes

BST

Binary search tree.

Find next element

Given one element, find the next one.

Algorithm:

  • if there is a right node
    • go right once, then down left all the way
    • next element must be on right subtree, and the first thing there is left all the way
  • else
    • go up until you come up from the left or the root is reached
      • if the root is reached from the right, it's over
    • if you come up from the left, the parent must be the next thing to be visited
    • if you come up from the right, the parent is smaller and has already been visited. TODO clearer proof that this works.

Delete element

Hard: https://en.wikipedia.org/wiki/Binary_search_tree#Deletion