Order 3: Min Max All leaf nodes have null pointers! Susan Cooper
Data 1 2
Pointers 2 3
1 Insert
46 46
2 Insert
55 46 55
3 Insert
88
55
46 88
4 Insert
99
55
46 88 99
5 Insert
200 88
Successor of 55 not full
Rotate left to insert 200 46 55 99 200
6 Insert
120
Both children are full
Evaluate and split median (120)
88 120
46 55 200
7 Insert
300
88 120
46 55 200 300
8 Insert
400
88 200
Successor of 120 not full
Rotate left to insert 400
46 55 99 120 300 400
9 Insert
500
All levels are full
200
Evaluate and split median (400)
Split and bring down 88 from 200 88 400
46 55 99 120 300 500
10 Insert
12
200
Both children are full
Evaluate and split median (46)
46 88 400
12 99 120 300 500
11 Insert
59
200
46 88 400
12 55 59 99 120 300 500
12 Insert
62
200
55 88 400
12 46 59 62 99 120 300 500
13 Insert
98
Left subtree is full
Evaluate and split median (99)
200
55 88 400
12 46 59 62 99 300 500
98 120
Bring 99 up to 55|88 and there is room in 400
Count on right of root (200) is one…room to rotate and combine 200 with 400
Bring the greatest value of left side (99) up to root
98 attaches to right of 88 and 120 is a jumper to left of 200|400
99
55 88 200 400
12 46 59 62 98 120 500
14 Insert
93
.
99
55 88 200 400
12 46 59 62 93 98 120 500
15 Insert
47
Evaluate and split median (46)
.
99
55 88 200 400
46 59 62 93 98 120 500
12 47
Both children of root (99) is full
Evaluate and split median of 46|55|88 up to root
55 99
46 200 400
12 47 59 62 93 98 120 500
Now delete all values in the order they were inserted
Start with…
55 99
46 200 400
12 47 59 62 93 98 120 500
1 Delete
46
Both pred. and succ. are same count
Swap with pred. (12) and delete 46
55 99
12 200 400
47 59 62 93 98 120 500
Cannont have null so combine 12 & 47
Combine 55 & 88
99
55 88 200 400
12 47 59 62 93 98 120 500
2 Delete
55
Both pred. & succ. have same count
Swap with pred. (47) and delete 55
99
47 88 200 400
12 59 62 93 98 120 500
3 Delete
88
Both pred. (62) & succ. (93) have same count
Swap with pred. (62) and delete 88
99
47 62 200 400
12 93 98 120 500
4 Delete
99
Pred. (98) has 1 more count than succ. (120)
Swap with pred. (98) and delete 99
98
47 62 200 400
12 93 120 500
5 Delete
200
Both pred. (120) & succ. (300) have same count
Swap with pred. (120) and delete 200
98
47 62 120 400
12 93 500
Combine 120 & 300
98
47 62 400
12 93 120 300 500
6 Delete
120
98
47 62 400
12 93 300 500
7 Delete
300
Delete 300 and combine 400 & 500
98
47 62 No elements
12 93 400 500
Need to borrow from left of root…rotate right
93 jumps to link to left of 98
62
47 98
12 59 93 400 500
8 Delete
400
62
47 98
12 59 93 500
9 Delete
500
Delete 500 and combine 93 & 98
62
47 No elements
12 59 93 98
Cannot borrow from left of root
Combine 47 & 62
47 62
12 93 98
10 Delete
12
Combine 47 & 59 62
47 59 93 98
11 Delete
59 62
47 93 98
12 Delete
62 93
47 98
13 Delete
98
47 93
14 Delete
93
47
15 Delete
47
DONE!!!