mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-24 13:24:05 -06:00
1.1 KiB
1.1 KiB
| title | aliases | tags | ||
|---|---|---|---|---|
| binary-search-tree | binary search tree, BST |
|
a collection of nodes with one distinguished node called the root
rules:
- the node data contains a key which comes from some ordered type e.g.,
string - each node can have at most who children - there are two fixed slots called left child and right child
- the left child node and it descendents are called the left subtree
- the key value at a nodes left child (and all its descendants) must be less than the key of the node
- the key value at a nodes right child (and all its descendants) must be greater than the key of the node
- we do not allow duplicate keys
Notation
- n.key for key
- n.l and n.r for left and right children
- n.p for its parent
- nil for a "not here" marker. e.g., n.r = nil means "n has no right child"
In this example:
- root.p = nil
- root.r = n
- n.p = root
- n.key = emu
- n.l = nil
- n.r.key = rat
