2019-05-03 in class

This commit is contained in:
Claudio Maggioni 2019-05-03 08:41:37 +02:00
parent 6958a25712
commit ddea8c08f8
1 changed files with 35 additions and 1 deletions

View File

@ -313,4 +313,38 @@ k <= a a <= k <= b k >= b
4. If a node is red, both of its children are black 4. If a node is red, both of its children are black
5. The black height is the same for every branch in the tree 5. The black height is the same for every branch in the tree
A red node is a way to strech the tree, but the A red node is a way to strech the tree, but you cannot stretch it too far.
# B-trees
Disk access sucks (a billion times slower than registers). So, ignore the RAM
model and come up with a better solution.
If the number of keys per node is increased to k keys, the complexity of tree
search will be log_k+1(n). We can search between the keys linearly because we
have to wait for the disks. And log_1000() is much better than log_2().
## Implementation
- Minimum degree (min. num. of children in each node) defined as `t` (`t >= 2`)
- Every node other than the root must have at least `t - 1` keys
- Every node must contain at most `2t - 1` keys
- Every node has a boolean flag for leaf
### Insertion
- Read node from disk
- If full, split
- If leaf, insert in the right position
- If not leaf, recurse on the right branch based on the keys
### Search
- Read node from disk
- Linearly search between keys
- If key found, return True
- otherwise, if leaf, return False
- otherwise, if not leaf, recurse on the right branch