The Ordering Rule of a Binary Search Tree
A binary search tree places items on sides of a node according to a comparison rule. The rule must hold across the entire corresponding subtree.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Trace one lookup
With root seven, left child four, and right child eleven, searching for five moves left and then right. An absent right child reports a missing value. Like binary search by hand, one comparison can eliminate a region when the ordering assumption holds.
Check a deep violation
Placing eight as the right child of four still violates seven's left-subtree requirement. Check bounds inherited from ancestors. Tree height also controls how many comparisons a lookup can need.[1]
Check the entire descendant range
A root key ten may have a left child five and a right child fifteen. Placing twelve to the right of five satisfies the immediate comparison with five but violates the root's required range for its left subtree. A validator should pass allowable bounds down the traversal. See tree height.
Enter root 10 with no bounds
Left child 5 requires key < 10
Right descendant of 5 there requires 5 < key < 10
Candidate key 12 fails the inherited upper bound
Declare how duplicates enter the structure
A search tree can store repeated counts in a node, store rows under a shared key, or adopt a tie-breaker. Use consistent order during insertion, search and deletion. A sorted insertion sequence can also form a chain unless the tree balances.