Leftist Trees Extended Binary Trees
Leftist Trees Extended Binary Trees
2 1 1 0 Otherwise,
s(x) = min {s(leftChild(x)),
1 1 0 0 1 0 s(rightChild(x))} + 1
0 0 0 0 0 0
A Leftist Tree
Height Biased Leftist Trees
2
1 1 0 0 1 0
0 0 0 0 0 0
A Leftist Tree
Leftist Trees – Property 1
2
1 1 0 0 1 0
0 0 0 0 0 0
0 0 0 0 0 0
put
4 3
removeMin()
6 8 5
meld()
8 6 9 initialize()
put() and removeMin() use meld().
Remove Min
Put Operation
2
put(7) 2
4 3
4 3
6 8 5
6 8 5
8 6 9
8 6 9
Remove the root.
Create a single node min leftist tree. 7
4 3 4 3
6 8 5 6 8 5 6
8 6 9 8 6 9
Meld Two Min Leftist Trees Meld Two Min Leftist Trees
4 3
4 3
6 8 5 6
6 8 5 6
8 6 9
8 6 9
Meld right subtree of tree with smaller root and Meld right subtree of tree with smaller root and all of
all of other tree. other tree.
Meld Two Min Leftist Trees Meld Two Min Leftist Trees
4 6 8 6
6 8
8 6
Meld right subtree of tree with smaller root and all of Meld right subtree of tree with smaller root and all of
other tree. other tree.
Right subtree of 6 is empty. So, result of melding right
subtree of tree with smaller root and other tree is the
other tree.
Meld Two Min Leftist Trees Meld Two Min Leftist Trees
6 4
8 4
6
6 6
Make melded subtree right subtree of smaller root. 6
8
6
8 6 8
8 6
8
Make melded subtree right subtree of smaller root.
Swap left and right subtree if s(left) < s(right). 6
5 4
4
5
6 6
9 6 6
9
8 6 8
8 6 8