Binary Search Tree Deep Dive
Understanding BST operations through interactive visualizations
BST Foundation
What is a Binary Search Tree?
A Binary Search Tree (BST) is a hierarchical data structure where:
- Each node has at most two children
- Left child < Parent < Right child
- All operations average O(log n) time
- In-order traversal gives sorted sequence
BST Search Operation
How Search Works
Starting from root, compare target with current node:
- If equal: Found!
- If target < current: Go left
- If target > current: Go right
- If null reached: Not found
BST Insert Operation
Building a Tree Step by Step
Watch how values [8,3,10,1,6,14,4,7,13] build our BST:
🧩 Visual Problem
Where would value 5 be inserted in our tree?
BST Delete Operation
Three Deletion Cases
- Leaf node: Simply remove
- One child: Replace with child
- Two children: Replace with inorder successor
BST Traversals
Three Traversal Methods
- Inorder: Left → Root → Right (sorted)
- Preorder: Root → Left → Right
- Postorder: Left → Right → Root
DFS on Large Graph
DFS on Complex Graph Structure
See how DFS works on the larger graph from the tutorial with 10 nodes:
- Stack-based execution shows deep exploration
- Creates a spanning tree structure
- Back edges connect to already visited vertices
- Similar to pre-order traversal pattern
Stack State:
🧩 DFS Pattern Recognition
What traversal pattern does DFS resemble?