BST
The notes
Definition and property
For each node: left subtree keys < node key < right subtree keys.
- Example tree: root 50, with children 30 and 70, and so on
- Terms shown: root, parent, children (left and right), leaves, edges
Key operations
Insertion (example: insert 35)
- Is 35 < 50? Yes, go left
- Is 35 > 30? Yes, go right
- Found the spot: attach as the right child
Searching (finding)
- Finding 60: 60 > 50, go right; 60 < 70, go left; find 60
- Finding 25 (not found): go left and right down to a NULL position, so it is not in the tree
Traversals
- In-order (left, root, right): visits in sorted order, e.g. [20, 30, 40, 50, 60, 70, 80]
- Pre-order (root, left, right): useful for copying, e.g. [50, 30, 20, 40, 70, 60, 80]
- Post-order (left, right, root): useful for deletion, e.g. [20, 40, 30, 60, 80, 70, 50]
Balance is key
- Balanced tree: efficient search, O(log N)
- Degenerate / skewed tree: slow search, O(N) (like a linked list)
Key takeaway. Balance is key: a balanced BST searches in O(log N), while a skewed one degrades to O(N).
Data structures deck
Make them stick
Sign in to see every card full size, tick the ones you've got, come back to the rest later, and keep your own notes on each card.
Watch the lesson
Data structures, Lesson 20, from 5:11: What is a Binary Search Tree








