CSData StructuresDiagramBeginner
Binary Search Tree
KO: 이진 탐색 트리·EN: Binary Search Tree·JA: 二分探索木·BST
A binary tree maintaining left < node < right ordering so search, insertion, and ordered range queries run in O(log N) on average
Table of Contents
Structure Diagram
Binary Search Tree (Left < Root < Right) StructureTap a node
ROOT50 (Root)
2 linksQuick Answer
What is Binary Search Tree?
A binary tree maintaining left < node < right ordering so search, insertion, and ordered range queries run in O(log N) on average. It is a core concept in Data Structures within CS.
Core Principles
A Binary Search Tree (BST) enforces the ordering invariant at every node: all keys in the left subtree are smaller, and all keys in the right subtree are larger.
- Logarithmic Operations: Starting at the root, each comparison discards half of the remaining tree, yielding
O(log N)search, insertion, and deletion when balanced. - In-order Traversal: Visiting
Left → Node → Rightoutputs all elements in sorted ascending order. - Skewed Degradation: Inserting already-sorted keys turns an unbalanced BST into a linked list, degrading performance to
O(N).
Practical Takeaways
- Use self-balancing variants in production: Libraries rely on Red-Black Trees or AVL Trees to rebalance via rotations and guarantee
O(log N)worst-case height. - BST vs Hash Table: Choose a hash table for
O(1)exact lookups; choose a balanced BST when you need sorted iteration, predecessor/successor queries, or range lookups (lower_bound). - Disk storage prefers B-Trees: Because each BST node holds one key, disk-backed databases generalize the concept into wide B+Trees to minimize I/O.
Notable Examples
- Standard Library Ordered Maps: C++
std::map, JavaTreeMap, and RustBTreeMap. - Linux CFS Scheduler: Uses a Red-Black Tree to pick the task with the smallest virtual runtime.
- Trading Order Books: Maintaining price levels in sorted order for fast matching.