From ddea8c08f8742a138f66502834e2d66c0e66fdd6 Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Fri, 3 May 2019 08:41:37 +0200 Subject: [PATCH] 2019-05-03 in class --- notes.md | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/notes.md b/notes.md index 03a707f..83f805b 100644 --- a/notes.md +++ b/notes.md @@ -313,4 +313,38 @@ k <= a a <= k <= b k >= b 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 -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 + + +