Ch 6: Balanced Trees I Flashcards

1
Q

what is a B-tree?

A

a tree with order K where nodes can have up to K-1 trees and up to K children

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

what is order?

A

the maximum number of children a node can have

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

what are the 5 properties of B-trees?

A
  • all keys in a B-tree must be distinct
  • all leaf nodes must be at the same level
  • an internal node with N keys must have N+1 children
  • keys in a node are stored in sorted order from smallest to largest
  • each key in a B-tree internal node has one left subtree and one right subtree. all left subtrees are < that key, and all right subtree keys are > that key
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what makes a node full?

A

a 2-3-4 tree node that has exactly 3 keys

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

what are the key labels of a 2-3-4 tree?

A

A,B,C

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

what are the child node labels of a 2-3-4 tree?

A

left, middle 1, middle 2, right

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

how many children can a node with K keys have?

A

K+1

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

explain the 2-3-4 tree search algorithm

A

returns the first node found matching that key, or returns null if a matching node is not found. Searching a 2-3-4 tree is a recursive process that starts with the root node. If the search key equals any of the keys in the node, then the node is returned. Otherwise, a recursive call is made on the appropriate child node. Which child node is used depends on the value of the search key in comparison to the node’s keys.

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

explain what the insert operation does

A

new keys are inserted into leaf nodes in a 2-3-4 tree, returns the leaf node where the key was inserted or null if the key was already in the tree

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

what is the split operation?

A

an operation that is executed on every full node encountered during insertion traversal

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

explain the split operation

A
  • moves middle from a child node into the child’s parent node
  • the first and last keys in the child node are moved into separate nodes
  • returns the parent node that received the middle key from the child
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

how many new nodes are allocated during split?

A
  • 2 when splitting an internal node

- 3 when splitting root

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

what is the preemptive split?

A

an insertion scheme that always splits any full node encountered during an insertion traversal

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

what does the preemptive split ensure?

A

ensures that any time a full node is split, the parent node has room to accommodate the middle value from the child

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

what is rotation?

A

a rearrangement of keys between 3 nodes that maintains all 2-3-4 tree properties in the process

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

what are the 2 different rotations? explain

A

right rotation - causes node to lose one key and the node’s right sibiling to gain one key
left rotation - causes node to lose one key and the node’s left sibling to gain one key

17
Q

does rotation allocate any new nodes?

A

no

18
Q

during delete, what type of nodes do rotations not operate on?

A

nodes that do not have a sibling with 2+ keys (nodes that have siblings with only 1 key)

19
Q

what is fusion?

A

an operation that is a combination of 3 keys: 2 from adjacent sibling nodes that have 1 key each, and a third from the parent of the siblings

20
Q

how is fusion related to split?

A

fusion is the inverse operation of split

21
Q

when is the root node a special case for fusion and explain what happens

A

special case: when root and root’s children each have 1 key

- the 3 keys from the 3 nodes are combined into a single node that becomes the new root node

22
Q

explain fusion operation for non-root nodes

A
  • operates on 2 adjacent siblings that each have 1 key
  • the key in the parent node that is between the 2 adjacent siblings is combined with the 2 keys from the two siblings to make a single, fused noe
  • parent node must have at least 2 keys
23
Q

what is merge?

A

an operation on a node with 1 key and increases the node’s keys to 2 or 3 using either rotation or fusion

24
Q

explain merge operation

A

A node’s 2 adjacent siblings are checked first during a merge, and if either has 2 or more keys, a key is transferred via a rotation. Such a rotation increases the number of keys in the merged node from 1 to 2. If all adjacent siblings of the node being merged have 1 key, then fusion is used to increase the number of keys in the node from 1 to 3.

25
Q

what type of node can merge operation be performed on?

A

a node that has 1 key and a non-null parent node with at least 2 keys

26
Q

what are the two possible cases when removing a key?

A
  • key is leaf node

- key is internal node

27
Q

what is the requirement for removal of a leaf node?

A

leaf node must have 2+ keys

28
Q

what is preemptive merge?

A

a removal scheme that involves increasing the number of keys in all single-key, non-root nodes encountered during traversal

29
Q

when does preemptive merge occur?

A

before any key removal is attempted

30
Q

what does preemptive merge ensure?

A

that any leaf node encountered during removal will have 2+ keys, allowing a key to be removed from the leaf node without violating the 2-3-4 tree rules

31
Q

explain removal operation

A

To remove a key from an internal node, the key to be removed is replaced with the minimum key in the right child subtree (known as the key’s successor), or the maximum key in the leftmost child subtree. First, the key chosen for replacement is stored in a temporary variable, then the chosen key is removed recursively, and lastly the temporary key replaces the key to be removed.