CPSC 320 – 2012W T1 1
CPSC 320: Intermediate Algorithm Design and Analysis
Amortized Analysis of Union/Find
- perations
Amortized Analysis of Union/Find operations CPSC 320 2012W T1 1 - - PowerPoint PPT Presentation
CPSC 320: Intermediate Algorithm Design and Analysis Amortized Analysis of Union/Find operations CPSC 320 2012W T1 1 Potential Function Relationships between a node N and its parent P: N is close if log 2 rank(N) = log 2
CPSC 320 – 2012W T1 1
CPSC 320 – 2012W T1 2
2 rank(N) ⌋ = ⌊ log 2 rank(P) ⌋.
CPSC 320 – 2012W T1 3
i is
N ∈D i
CPSC 320 – 2012W T1 4
2 rank(P) ≥ log 2
2 rank(P) ⌋ > ⌊ log 2 rank(N) ⌋.
k then ⌊ log 2 rank(P) ⌋ - ⌊ log 2 rank(N) ⌋ < rank(N)
2 rank(P)⌋ - ⌊log 2 rank(N)⌋ ≤ k - ⌊log 2 (k+1)⌋ <
CPSC 320 – 2012W T1 5
real(makeSet) ∈ Θ(1).
am(makeSet) ∈ Θ(1).
CPSC 320 – 2012W T1 6
0, x 1, ..., x l-1, x l
real(find) = l + 1.
j) change?
0, x 1, ..., x l-1, x l.
j) goes down by at least
j's
CPSC 320 – 2012W T1 7
l-1 or x l
l-1 and x l do not move. Hence neither ϕ(x l-1) nor
l) changes.
l) > rank(P).
CPSC 320 – 2012W T1 8
CPSC 320 – 2012W T1 9
l) > rank(P).
l) < 3 rank(N) – rank (P).
CPSC 320 – 2012W T1 10
CPSC 320 – 2012W T1 11
2 rank(N) ⌋ –
2 rank(x l) ⌋, which by observation 2 is smaller than
CPSC 320 – 2012W T1 12
am(find) ≤ l + 1 - (l + 1 - (log* n + 3)).
am(find) ∈ O(log* n).
CPSC 320 – 2012W T1 13
l becomes a child of y l.
real(union) ∈ Θ(1).
l) was 3 rank(x l) before the union, and is now either 3
l) – rank(y l), or rank(x l) + ⌊ log 2 rank(x l) ⌋ – ⌊ log 2
l) ⌋, or 0 after the union.
l) has decreased.
CPSC 320 – 2012W T1 14
l) increases, then ϕ(y l) will increase by 3.
l may
am(union) ∈ O(log* n).