B-trees deletion Flashcards

1
Q

(1) k in x && x (is leaf) then…what do we do

A

delete the key k from x

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Describe an optimisation made for deletion

A
  • Want to guarantee that whenever deletion calls itself recursively on a node x, #Keys(x) >= t (rather than >= t-1)
  • So sometimes a key may have to be moved into a child before recursion descends to that child.
  • Allows deletion in one downward pass without having to “back up” (one exception).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What happens if a root node x ever becomes an internal node with no keys

A

delete the empty node x,
x’s only child x.c becomes the new root of the tree
decreases tree height by one
preserves property that root of tree contains at least one key (unless tree is empty).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Case 1: key k is in node x and x is a leaf

A

delete key k from x

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

State condition for case 2

A

Case 2: Key k is in node x, and x is an internal node

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe case 2a of deletion

A

Case 2: Key k is in node x, and x is an internal node

2a if child y preceding k in node x has >= t keys

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe what to do in case 2a of deletion

A

2a if child y preceding k in node x has >= t keys, find predecessor k’ of k in subtree rooted at y, recursively delete k’ and replace k by k’ in x (we can find k’ and delete it in a single downward pass.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Describe case 2b of deletion

A

Case 2: Key k is in node x, and x is an internal node

2b If y has fewer than t keys, then (symmetric to 2a)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What do we do in case 2b of deletion

A

2b If y has fewer than t keys, then (symmetric to 2a) examine child z that follows k in node x,
if z has at least t keys, then find the successor k’ of k in the subtree rooted at z. Recursively delete k’, and replace k by k’ in x (We can find k’ and delete it in a single downward pass).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

State case 2c of deletion

A

2c If both y and z have only (t - 1) keys,

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

State what to do in case 2c of deletion

A

2c If both y and z have only (t - 1) keys, merge k and all of z into y $ x loses both k and the pointer to z, and y now contains 2t-1 keys. Then free the page allocated to node z, and recursively delete k from y.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

State what to do in case 3 generally,

A

if k is not present in the internal node x,
then find the root of the appropriate subtree that must contain k, (if k is in the tree at all).

if the child has only t-1 keys execute step 3a or 3b as necessary to guarantee that we descend to a node containing at least t keys.

Then finish by recursing on the appropriate child of x.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Condition for case 3a

A

if the child x.c where k could possibly exist has only t-1 keys, but has an immediate sibling with at least t keys, give x.c an extra key by moving a key from x down int x.c, moving a key from x.c’s immediate left or right sibling up into x, and moving the appropriate child pointer from the sibling into x.c.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Condition for case 3b

A

if x.c and both of x.c’s immediate siblings have t-1 keys

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What to do in case 3a

A

give x.c an extra key by moving a key from x down int x.c, moving a key from x.c’s immediate left or right sibling up into x, and moving the appropriate child pointer from the sibling into x.c.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What to do in case 3b

A

merge x.c with one sibling, which involves moving a key from x down into the new merged node to become the median key for that node

17
Q

State the signature of the delete function

A

Delete a key K takes the key K, and the root on which to delete from (nodes are given symbols x, y, z)…

so top level call will be DELETE(K, T.root)