Date post: | 14-Apr-2018 |
Category: |
Documents |
Upload: | manishbhardwaj8131 |
View: | 243 times |
Download: | 2 times |
of 19
7/27/2019 Bottom Up Splay Trees
1/19
Bottom-Up Splay TreesAnalysis
Actual and amortized complexity of join is
O(1).
Amortized complexity of search, insert, delete,and split is O(log n).
Actual complexity of each splay tree operation
is the same as that of the associated splay. Sufficient to show that the amortized
complexity of the splay operation is O(log n).
7/27/2019 Bottom Up Splay Trees
2/19
Potential Function
size(x) = #nodes in subtree whose root is x. rank(x) = floor(log2 size(x)).
P(i) = Sx is a tree node rank(x).
P(i) is potential afterith operation.
size(x) and rank(x) are computed afterithoperation.
P(0) = 0.
When join and split operations are done,number of splay trees > 1 at times.
P(i) is obtained by summing over all nodes in
all trees.
7/27/2019 Bottom Up Splay Trees
3/19
Example
size(x) is in red.
20
10
6
8
40
30
1
rank(x) is in blue.
Potential = 5.
2
3
1
2
6
0
1
1
0
1
2
7/27/2019 Bottom Up Splay Trees
4/19
Root Rank
rank(root) = floor(log2 n).
20
10
6
8
40
30
1
2
3
1
2
6
0
1
1
0
1
2
7/27/2019 Bottom Up Splay Trees
5/19
Insert
On every leaf to root path ranksare non-decreasing.
At most floor(log2 n)+1 different
ranks on such a path.
Insert may increase the rank of
only the last node in each sequence
of equal rank nodes.
When you insert, potentialincreases by up to floor(log2 n)+1. 0
1
1
4
4
4
7
7/27/2019 Bottom Up Splay Trees
6/19
Join
Rank of root is floor(log2 n).
Other ranks unchanged.
Potential increases by floor(log2 n).
S
m
B
7/27/2019 Bottom Up Splay Trees
7/19
Splay Step Amortized Cost
Ifq = null orq is the root, do nothing (splay
is over). DP = 0.
amortized cost = actual cost +DP
= 0.
7/27/2019 Bottom Up Splay Trees
8/19
Splay Step Amortized Cost
Ifq is at level 2, do a one-level move andterminate the splay operation.
p
q
a b
c
b c
a
q
p
r(x) = rank ofxbefore splay step.
r(x) = rank ofx after splay step.
7/27/2019 Bottom Up Splay Trees
9/19
Splay Step Amortized Cost
p
q
a b
c
b c
a
q
p
DP = r(p) + r(q) r(p)r(q)
7/27/2019 Bottom Up Splay Trees
10/19
2-Level Move (case 1)
DP = r(gp) + r(p) + r(q) r(gp) r(p)r(q)
p
q
a b
c
gp
d
c d
b
p
gp
q
a
7/27/2019 Bottom Up Splay Trees
11/19
2-Level Move (case 1)
r(q) = r(gp)
r(p)
7/27/2019 Bottom Up Splay Trees
12/19
2-Level Move (case 1)
DP = r(gp) + r(p) + r(q) r(gp) r(p)r(q)
r(q) = r(gp)
r(gp)
7/27/2019 Bottom Up Splay Trees
13/19
2-Level Move (case 1)
A more careful analysis reveals that
DP
7/27/2019 Bottom Up Splay Trees
14/19
2-Level Move (case 1)
amortized cost = actual cost +DP
7/27/2019 Bottom Up Splay Trees
15/19
2-Level Move (case 2)
Similar to Case 1.
7/27/2019 Bottom Up Splay Trees
16/19
Splay Operation
When q != null and q is not the root, zero or
more 2-level splay steps followed by zero or
one 1-level splay step.
Let r(q) be rank ofq just after last 2-level
splay step.
Let r(q) be rank ofq just after1-level
splay step.
7/27/2019 Bottom Up Splay Trees
17/19
Splay Operation
Amortized cost of all 2-level splay steps is
7/27/2019 Bottom Up Splay Trees
18/19
Actual Cost Of Operation
Sequence
Actual cost of an n operation sequence
=O(actual cost of the associated n splays).
actual_cost_splay(i) = amortized_cost_splay(i)DP
7/27/2019 Bottom Up Splay Trees
19/19
Actual Cost Of Operation
Sequence
actual_cost_splay(i) = amortized_cost_splay(i)DP