Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Extended tree.
Tree in which all empty subtrees are replaced by new nodes that are called external nodes. Original nodes are called internal nodes.
external node
internal node
Example-1
Example-2
A leaf node has no children, but can still contain one, two, or three data items ( 2, 3, or 4 links); cannot be empty. In a 2-3-4 tree, nodes with a single link are NOT permitted; a node with one data item must have two links (unless its a leaf); nodes with two data items must have three children; nodes with three data items must have four children.
Points to nodes w/keys < A ; Nodes with key between A and <B
See below: (Equal keys not permitted; leaves all on same level; upper level nodes often not full; tree balanced! Its construction always maintains its balance, even if you add additional data items. (ahead)
50
2-node
30
2-node
60
70
80 4-node
10 20
40
55
62 64 66
75
83 86
Else
Select the link that leads to the appropriate subtree with the appropriate range of values. If you dont find your target here, go to next child. (notice data items are sequential.) Data will ultimately be
found or not found.
30
2-node
60
70
80 4-node
10 20
40
55
62 64 66
75
83 86
Note: Nodes serve as holders of data and holders of indexes. Note: can easily have a no hit condition Note: the sequential nature after indexingsequential searching within node.
13
Efficiency of Search
Searching: 2-3-4 Trees: one node must be visited, but
More data per node / level. Searches are fast.
recognize all data items at node must be checked in a 2-3-4 tree, but this is very fast and is done sequentially.
Otherwise, push the middle value up into the parent node. Ascend into the parent node.
Find the child whose interval contains the value to be inserted. If that child is a leaf, insert the value into the child node and finish.
Otherwise, descend into the child and repeat from step 1
Insert 2
12
Insert 15
12
Insert 12
15
10
15
Insert 10
15
15
8 10
15 25
8 10
15 25 35
Insert 4
Insert 25
4 12 25
Insert 35
12
25
8 10
15
15
35
8 10
15
35 55
Insert 55
Example (Cont)
12 4 25
Insert 11, 9, 5
12 4 25
10
15
35
55
10 11
15
35
55
Insert 11
12 25
11
15
35
55
11
15
35
55
Insert 9
Example (Cont)
12 4 10 25
Insert 5, 7
12 4 8 10 25
5 8 9
11
15
35
55
11
15
35
55
Insert 5
12 4 8 10
25
11
15
35
55
(4) q is a 2-node, and its nearest sibling, r, is a 3-node. (rotation) (5) q is a 2-node and its nearest sibling, r, is a 4-node. (rotation)