Title: 23 trees
12-3 trees Damien Filiatrault 03-23-2004
2B-tree (data structure) Definition A balanced
search tree in which every node has between m/2
and m children, where m1 is a fixed integer. m
is the order. The root may have as few as 2
children. This is a good structure if much of the
tree is in slow memory (disk), since the height,
and hence the number of accesses, can be kept
small, say one or two, by picking a large m.
source http//www.nist.gov/dads/HTML/btree.html
3Why it is useful to use high-order b-trees saving
application data on hard disk rather than in main
memory
4Example of a 2-3 tree
4 10
3 x
7 x
13 27
1
3
4
7
10
13
27
2-3 trees are a data structure commonly used to
implement ordered lists of records. A 2-3 tree
is a tree satisfying the following
requirements - All internal nodes in the tree
have either two or three children. - All leaves
of the tree are at the same level.
5Same tree after adding the element
8
4 10
Fork
3 x
7 8
13 27
Leaf
1
3
4
7
10
13
27
8
Each fork contains the following indices - the
least element in child 2. - the least element in
child 3 (if not empty).
6Same tree after adding the element
9
4 10
3 x
7 8
13 27
1
3
4
7
10
13
27
8
9
To insert a new leaf l in a 2-3 tree, locate the
position where the new leaf should be inserted
and add the new leaf to the tree. Call p the
parent of the newly inserted leaf. If the number
of children of p has increased from two to three,
we still have a 2-3 tree and no further change is
needed. If the number of children of p has
increased from three to four, split p into two
nodes with two children each, incrementing the
number of children of p's parent. Proceed
recursively up to the root of the tree, and, if
needed, add a new root to augment the height of
the tree by one.
source http//theory.lcs.mit.edu/miccianc/inccry
pto/23trees.html
7Insertion continued
4 8
3 x
7 x
13 27
9 x
1
3
4
7
10
13
27
8
9
To insert a new leaf l in a 2-3 tree, locate the
position where the new leaf should be inserted
and add the new leaf to the tree. Call p the
parent of the newly inserted leaf. If the number
of children of p has increased from two to three,
we still have a 2-3 tree and no further change is
needed. If the number of children of p has
increased from three to four, split p into two
nodes with two children each, incrementing the
number of children of p's parent. Proceed
recursively up to the root of the tree, and, if
needed, add a new root to augment the height of
the tree by one.
source http//theory.lcs.mit.edu/miccianc/inccry
pto/23trees.html
8Insertion completed.
8 x
10 x
4 x
3 x
7 x
13 27
9 x
1
3
4
7
10
13
27
8
9
To insert a new leaf l in a 2-3 tree, locate the
position where the new leaf should be inserted
and add the new leaf to the tree. Call p the
parent of the newly inserted leaf. If the number
of children of p has increased from two to three,
we still have a 2-3 tree and no further change is
needed. If the number of children of p has
increased from three to four, split p into two
nodes with two children each, incrementing the
number of children of p's parent. Proceed
recursively up to the root of the tree, and, if
needed, add a new root to augment the height of
the tree by one.
source http//theory.lcs.mit.edu/miccianc/inccry
pto/23trees.html
9Deletion
The deletion of a leaf from a 2-3 tree is
performed analogously. First the leaf is located
and removed. Call p the parent of the removed
leaf. If the number of children of p has
decreased from three to two, the tree is still
2-3. If the number of children of p has decreased
from two to one, merge p with one of its
siblings, possibly reducing the number of
children of p's parent. Proceed recursively, up
to the root of the tree. If at the end the root
has degree one, romove it and make its child
become root.
source http//theory.lcs.mit.edu/miccianc/inccry
pto/23trees.html
10Complexity 1log3n 1log2n The time to search, insert or delete is
O(log n).
source http//www.csse.monash.edu.au/lloyd/tilde
AlgDS/Tree/23tree/