Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.
-
date post
21-Dec-2015 -
Category
Documents
-
view
213 -
download
0
Transcript of Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.
![Page 1: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/1.jpg)
Workshop Leader Interest Meeting
Today 5:15PM LAS – Basement of Lattimore
![Page 2: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/2.jpg)
AVL Trees
CSC 172
SPRING 2004
LECTURE 17
![Page 3: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/3.jpg)
A PROBLEM WITH BSTs
Common operations on balanced BST are O(log(n))
Alas, when the tree goes out of balance, performance degrades (worst case : chain O(n))
There are several data structures that modify the BST to maintain balance.
![Page 4: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/4.jpg)
BST Structure : Log & Linear
![Page 5: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/5.jpg)
Permutations of 1,2,3
![Page 6: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/6.jpg)
AVL Trees
The first balanced binary search tree
Named after discoverers Adelson-Velskii and Landis.
DEFINITION:An AVL tree is a binary search tree with the additional
balance property that, for any node in the tree, the height of the left and right subtrees can differ by at most 1. (Height of an empty subtree is –1).
![Page 7: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/7.jpg)
12
8 16
2 6
4 10 14
AN AVL TREE
What if we insert “7”?-1 -1 -1 -1
-1 -1 -1 -1
-1
0 0
001
12What is the height?
3
![Page 8: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/8.jpg)
12
8 16
2 6
4 10 14
NOT AN AVL TREE
-1 -1
-1 -1
-1 -1 -1 -10 1
002
13
4
-1
7
-1 0
Out of balance
![Page 9: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/9.jpg)
AVL THEOREMAn AVL tree of n element has height O(log n)
In fact, An AVL tree of height H has at least FH+3 –1 nodes, where Fi is the ith Fibonacci number
![Page 10: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/10.jpg)
AVL THEOREMLet SH be the size of smallest AVL tree of height H.
Clearly S0=1 and S1=2
SH must have subtrees of height H-1 and H-2
These subtrees must have fewest nodes for height
So, SH = SH-1 + SH-2 + 1
Minimum number AVL trees are Fibonacci trees
![Page 11: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/11.jpg)
Smallest AVL Tree of height H
SH-
1
H-1SH-
2
H-2
H
![Page 12: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/12.jpg)
SH = FH+3 – 1
FH+3 – 1 >= (3/2)H // do this as exercise
Hint: (3/2)H-1+(3/2)H=(3/2)H-2(3/2 + 1) > (3/2)H-2(9/4)
SH >= (3/2)H
Log2(SH) >= H Log2(3/2)
H <= 1.75 Log2(SH)
![Page 13: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/13.jpg)
Adds can unbalance a BST
Only nodes on the path from the root to the insertion point can have their balances altered
If we restore the unbalance node, we balance the tree
![Page 14: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/14.jpg)
12
8 16
2 6
4 10 14
AN AVL TREE
What if we insert “15”?
-1 -1 -1 -1
-1 -1 -1 -1
-1
0 0
001
12
3
If we insert 7We unbalance the whole tree
![Page 15: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/15.jpg)
12
8 16
2 6
4 10 14
AN AVL TREE
What if we insert “15”?
-1 -1 -1 -1
-1 -1 -1
-1
0 0
101
22
3
If we insert 7We unbalance the whole tree
15-1 -1
0
![Page 16: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/16.jpg)
4 cases
1. Insertion in left sub-tree of left child
2. Insertion in right sub-tree of left child
3. Insertion in left sub-tree of right child
4. Insertion in right sub-tree of right child
1 & 4 are symmetric
2 & 3 are symmetric
![Page 17: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/17.jpg)
Cases 1 & 4
A B
C
k1
k2Insertion extends Tree ‘A’
HH-2
H-2 H-2
![Page 18: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/18.jpg)
Cases 1 & 4
A B
C
k1
k2Insertion extends Tree ‘A’
H-2
H-1 H-2
“Rotation” fixesbalance
![Page 19: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/19.jpg)
Cases 1 & 4
AB C
k2
k1Insertion extends Tree ‘A’
H-2H-1 H-2
“Rotation” fixesbalance
H
![Page 20: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/20.jpg)
Cases 2 & 3
A B
C
k1
k2Insertion extends Tree ‘B’
HH-2
H-2 H-2
![Page 21: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/21.jpg)
Cases 2 & 3
A B
C
k1
k2Insertion extends Tree ‘B’
H-2
H-2 H-1
![Page 22: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/22.jpg)
Cases 2 & 3
AB C
k2
k1Insertion extends Tree ‘B’
H-2H-2 H-1
“Rotation” Does not fixbalance
![Page 23: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/23.jpg)
Double Rotation
If x is out of balance for cases 2&3
1. Rotate between X’s child and grandchild
2. Rotate between X and it’s new child
![Page 24: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/24.jpg)
Cases 2 & 3
A B
C
k1
k2Insertion extends Tree ‘B’
HH-2
H-2 H-2
![Page 25: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/25.jpg)
Cases 2 & 3
A C
D
k1
k2Insertion extends Tree ‘B’ or ‘C’
HH-2
H-2 H-3
k3
B
![Page 26: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/26.jpg)
Cases 2 & 3
A C
D
k1
k2Insertion extends Tree ‘B’ or ‘C’
H-2
H-2 H-2
k3
B
Rotate grandchildWith child
![Page 27: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/27.jpg)
Cases 2 & 3
AC
D
k3
k2Insertion extends Tree ‘B’ or ‘C’
H-2
H-2
H-2
k1
B
Rotate grandchildWith child
Rotate X with new child
![Page 28: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/28.jpg)
Cases 2 & 3
A C D
k2
k3Insertion extends Tree ‘B’ or ‘C’
H-2
H-2
H-2
k1
B
Rotate grandchildWith child
Rotate X with new child
![Page 29: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/29.jpg)
Implementation
Insert
Fixup
Rotate
Need to keep track of balance
![Page 30: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/30.jpg)
Rotationprivate void rotateLeft(Node p) {
Node r = p.right;p.right = r.left;if (r.left != null) r.left.parent = p;r.parent = p.parent;if (p.parent == null) {root = r; r.parent = null;}else if (p.parent.left == p) p.parent.left = r;else p.parent.right = r;r.left = p;p.parent = r;
}
![Page 31: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/31.jpg)
element left right parentroot
50
80
![Page 32: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/32.jpg)
element left right parentroot
50
80
90
r
Entry r = p.right;
p
![Page 33: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/33.jpg)
element left right parentroot
50
80
90
r
Entry r = p.right;p.right = r.left;
p
![Page 34: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/34.jpg)
element left right parentroot
50
80
90
r
Entry r = p.right;p.right = r.left;if (r.left != null) r.left.parent = p;if (p.parent == null)root = r; r.parent = p.parent;
p
![Page 35: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/35.jpg)
element left right parentroot
50
80
90
r
Entry r = p.right;p.right = r.left;if (r.left != null) r.left.parent = p;r.parent = p.parent;if (p.parent == null) root = r;else if …else …r.left = p;
p
![Page 36: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/36.jpg)
element left right parentroot
50
80
90
r
Entry r = p.right;p.right = r.left;if (r.left != null) r.left.parent = p;r.parent = p.parent;if (p.parent == null){ root = r; ..}else if …else …r.left = p;p.parent = r;
p
![Page 37: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/37.jpg)
Node classprivate static class Node {
Object element;char balanceFactor = ‘=‘; // new nodes are balanced// we could set this to R or L indicating child with > heightNode left = null, right = null, parent;Node (Object element, Entry parent) {
this.element = element;this.parent = parent;
}}
![Page 38: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/38.jpg)
50
R
20
L
10
=
80
R
70
=
100
=
92
=
50
=
![Page 39: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/39.jpg)
public boolen add(Object o){
if (root == null) {
root = new Node(o,null);
size++;
return true;
}// empty tree
else {
Node temp = root,
ancestor = null; // we keep track of nearest unbalanced ancestor
int comp;
while (true) {
comp = ((Comparable)o).compareTo(temp.element);
if (comp == 0) return false;
![Page 40: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/40.jpg)
if (comp < 0) {
if (temp.balanceFactor != ‘=‘) ancestor = temp;
if (temp.left != null) temp = temp.left;
else {
temp.left = new Entry(o,temp);
fixAfterInsertion(ancestor,temp.left);
size++;
}
}// comp < 0
![Page 41: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/41.jpg)
else { // comp > 0
if (temp.balanceFactor != ‘=‘) ancestor = temp;
if (temp.right != null) temp = temp.right;
else {
temp.rig = new Node(o,temp);
fixAfterInsertion(ancestor,temp.right);
size++;
}
}// comp < 0
}// while
}// root not null
}//method add
![Page 42: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/42.jpg)
Adjusting paths50
=
25
=
15
=
70
=
60
=
30
=
55
=
90
=
![Page 43: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/43.jpg)
Adjusting paths50
R
25
=
15
=
70
L
60
L
30
=
55
=
90
=
![Page 44: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/44.jpg)
protected void adjustPath(Entry to, Entry inserted) {
Object o = inserted.element;
Node temp = inserted.parent;
while (temp != to) {
if (((Comparable)o).compareTo(temp.element)<0)
temp.balanceFactor = ‘L’;
else
temp.balanceFactor = ‘R’;
temp= temp.parent
}// while
} //adjust path
![Page 45: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/45.jpg)
protected void fixAfterInsertion(Node ancestor, Entry inserted) {
Object o = inserted element;
if (ancestor == null) {
if (((Comparable)o).compareTo(root.element)<0)
root.balanceFactor = ‘L’;
else
root.balanceFactor = ‘R’;
adjustPath(root,inserted);
} // Case 1: all ancestor of inserted element have ‘=‘ balanceFactor
![Page 46: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/46.jpg)
if ((ancestor.balanceFactor == ‘L’ &&
((Comparable)o).compareTo(ancestor.element)>0)||
(ancestor.balanceFactor == ‘R’ &&
((Comparable)o).compareTo(ancestor.element)<0)){
ancestor.balanceFactor = ‘=’;
adjustPath(ancestor,inserted);
} // Case 2: insertion causes ancestor’s balanceFactor to ‘=‘
![Page 47: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/47.jpg)
if ((ancestor.balanceFactor == ‘R’ &&
((Comparable)o).compareTo(ancestor.right.element)>0){
ancestor.balanceFactor = ‘=’;
rotateLeft(ancestor);
adjustPath(ancestor.parent,inserted);
} // Case 3: ancestor’s balance factor = ‘R’
// and o > ancestor’s right child
![Page 48: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/48.jpg)
if ((ancestor.balanceFactor == ‘L’ &&
((Comparable)o).compareTo(ancestor.left.element)<0){
ancestor.balanceFactor = ‘=’;
rotateRight(ancestor);
adjustPath(ancestor.parent,inserted);
} // Case 4: ancestor’s balance factor = ‘L’
// and o < ancestor’s right child
![Page 49: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/49.jpg)
if (ancestor.balanceFactor == ‘L’ &&
((Comparable)o).compareTo(ancestor.left.element)>0){
rotateLeft(ancestor.left);
rotateRight(ancestor);
adjustLeftRight(ancestor,inserted);
} // Case 5: ancestor’s balanceFactor = ‘L’
// and o > ancestor’s left child
![Page 50: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/50.jpg)
else{
rotateRight(ancestor.right);
rotateLeft(ancestor);
adjustRightLeft(ancestor,inserted);
} // Case 6: ancestor’s balanceFactor = ‘R’
// and o < ancestor’s right child
}// fixAfterInsertion
![Page 51: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/51.jpg)
protected void adjustLeftRight(Entry ancestor, Entry inserted) {
Object o = inserted.element;
if (ancestor.parent == inserted) ancestor.balanceFactor = ‘=‘;
else if (((Comparable)o).compareTo(ancestor.parent.element)<0){
ancestor.balanceFactor = ‘R’;
adjustPath(ancestor.parent.left,inserted);
}// o < ancestor’s parent
else {
ancestor.balanceFactor = ‘=’;
ancestor.parent.left.balanceFactor = ‘L’;
adjustPath(ancestor,inserted);
}// while
} //adjustLeftRight
![Page 52: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/52.jpg)
AdjustLeftRight Case 1
50
L
30
=
40
=
50
=
40
=
30
=
![Page 53: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/53.jpg)
AdjustLeftRight Case250
L
10
=5
=
15
=35
=
40
=30
=
45
=
20
=
90
=
70
=
100
=Rotate Left around 20Right around 50
![Page 54: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/54.jpg)
AdjustLeftRight Case240
=
10
=5
=
15
=
30
R35
=
20
=
50
R
45
=
90
=70
=
100
=
![Page 55: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/55.jpg)
AdjustLeftRight Case350
L
10
=5
=
15
=42
=
40
=30
=
45
=
20
=
90
=
70
=
100
=Rotate Left around 20Right around 50
![Page 56: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/56.jpg)
AdjustLeftRight Case340
=
10
=5
=
15
=
30
=42
=
20
L
50
=
45
L
90
=70
=
100
=
![Page 57: Workshop Leader Interest Meeting Today 5:15PM LAS – Basement of Lattimore.](https://reader030.fdocuments.in/reader030/viewer/2022032704/56649d6d5503460f94a4d8fd/html5/thumbnails/57.jpg)
protected void adjustRightLeft(Entry ancestor, Entry inserted) {
Object o = inserted.element;
if (ancestor.parent == inserted) ancestor.balanceFactor = ‘=‘;
else if (((Comparable)o).compareTo(ancestor.parent.element)>0){
ancestor.balanceFactor = ‘L’;
adjustPath(ancestor.parent.right,inserted);
}// o < ancestor’s parent
else {
ancestor.balanceFactor = ‘=’;
ancestor.parent.right.balanceFactor = ‘R’;
adjustPath(ancestor,inserted);
}// while
} //adjustRightLeft