Beruflich Dokumente
Kultur Dokumente
4)! If a node is red, then both its children are black. Every node has a
2! 18! 1! 22! black-height, bh(x).
5)! For each node x, all paths from x to its descendant
1! 17! 1! 19! 1! 21! 1! 25! For all NIL leaves,
leaves contain the same number of black nodes.
bh(x) = 0.
0! 0! 0! 0! 0! 0! 0! 0!
20!
For root x,
18! 22! bh(x) = bh(T).
18! 22!
20!
20!
18! 22!
18! 22! +2!
17! 19! 21! 25!
17! 19! 25! -1!
23! 0!
Inserting or deleting a node from an AVL tree can cause some node to
have a balance factor of +2 or -2, in which case the algorithm causes
rotations of particular branches to restore the 0, +1 or -1 balance factor
at each node.
+!
-!
+!
-!
-! +!
+! -!
AVL Trees! AVL rotation practice!
When a node is inserted and causes an imbalance as shown on the last For each of these trees, indicate whether they are AVL trees by showing
slide, one of 4 possible rotations take place to restore the balance in the the balance factor at each node.
tree.
0! 0!
20! In this case, an RL rotation
occurs, producing the tree -1! -3!
22! +2! 0! -1!
18! shown below. 2!
2! -1! 0! -1! 1! 0!
17! 19! 25! -1! -1!
20! -1! 0! 0! 0!
23!
0! 0!
0! 0! 0!
18! 23! 0!
Basic operation is called splaying. Splaying the tree for a certain element
rearranges it so that the element is placed at the root of the tree.
Performs a standard BST search and then does a sequence of rotations to
bring the element to the root of the tree.
Frequently accessed nodes will move nearer to the root where they can
be accessed more quickly. These trees are particularly useful for
implementing caches and garbage collection algorithms.
A 2-3 tree of height h with the smallest number of keys is a full tree of 2 When a node with 4 keys is created, the tree is reordered in a similar
nodes (height = $(lgn)). A 2-3 tree of height h with largest number of fashion as a 2-3 tree.
keys is a full tree of 3 nodes, each with 2 keys and 3 children (height =
$(log3n). Therefore, all operations are $(lgn). You are not expected to know how to perform any operations on a 2-3-4
tree.
B-Trees! B-Trees!
Developed by Bayer and McCreight in 1972. A B-Tree of order m (the maximum number of children for each node) is
a tree which satisfies the following properties :
Our text covers these trees in Chapter 18.
1. Every node has at most m and at least m/2 children.
B-trees are balanced search trees designed to work well on magnetic 2. The root has at least 2 children.
disks or other secondary-storage devices to minimize disk I/O operations. 3. All leaves appear in the same level, and carry no information.
Extends the idea of the 2-3 tree by permitting more than a single key in 4. A non-leaf node with k children contains k -1 keys
the same node.
B-trees have substantial advantages over alternative
Internal nodes can have a variable number of child nodes within some
implementations when node access times far exceed
pre-defined range, m.
access times within nodes. "
You are not expected to know anything more about B-Trees (unless
someone chooses this topic to present).
Mini-Homework 5!
due Tuesday, March 24th !
1.! Give the binary search tree that results from inserting the following
keys, in left to right order: 67, 12, 72, 19, 14, 54, 76, 23, 9, 17.
Showing the final tree will suffice.
2.! Show the binary search tree from part 1 after the key 19 is deleted.
3.! Insert the keys 5, 6, 8, 3, 2, 4, 7 into an AVL tree in the left to right
order given. List the balance factor at each node after each new key
is inserted and show all rotations.
4.! Insert the keys given in problem 3 into a 2-3 tree in the left to right
order shown. Show each insertion step and any overloads that cause
nodes to split.