Download UF - Tel Aviv University

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Lecture overview
•Single operation time complexity
•Previous results
•Optimality proof
•UF(k)-trees
•Operations and complexity
•IUF(k)-trees
•Properties and complexity
Single operation complexity
A data structure in which each UNION operation can be performed
in O(k), and each FIND operation can be performed in time
O(logkn).
k is a parameter, 2  k  n .
Previous algorithms had operation complexity (log n).
If we choose k = log n / log log n,
UNION: O(k) = O(log n / log log n)
FIND: O(logkn) = O(log n / log log n)
Single operation complexity
log n
k
log log n
Union: O(k)
Find: O(logkn)
log n
log n
log k n 


log k log( log n )
log log n
log n
log n
 O(
)
log log n  log log log n
log log n
Optimal data structure
Theorem (Blum): Suppose that every UNION operation can be
performed in O(k). Then there is a FIND operation that needs
time
log n
(
)
log k  log log n
Corollary: There is always either a UNION or a
FIND operation that takes
log n
(
)
log log n
Optimal data structure
log n
k
log log n
log n
log n


log k  log log n log( log n )  log log n
log log n
log n
log n

2 log log n  log log log n 2 log log n
Optimal data structure

k  (log n) ,   0
log k   log log n
log k   log k   log log n   log k
(  1) log k   (log log n  log k )
log n
log n

(  1) log k  (log log n  log k )

log n
log k n 
 1
log log n  log k
UF(k)-trees
Let k be an integer, 2  k  n. A tree T is called a
UF(k)-tree , if
The root of T has at most k sons.
Each node in T has either 0 or more than k grandsons.
All leaves of T have the same depth.
UF(k)-tree structure
name
sons
number of sons
height
leaf
UK(k)-tree structure
Elements are stored at the leaves
a
b
c
d
e
To FIND an element, climb to the root
f
g
h
UK(k)-tree structure
Initially all trees are of size 2.
a
b
c
d
e
f
UF(k)-trees - balanced
If level i contains any nodes, it contains at least ki/2 nodes.
The tree has at most n leaves
Height  2logkn
FIND : O(logkn)
UF(k)-trees - linear
UF(k)-trees - linear
UF(k) - case 1
Total number of sons  k
UF(k) - case 1
Total number of sons  k
UF(k) - case 2
Total number of sons > k
UF(k) - case 2
Total number of sons > k
UF(k) - case 3
UF(k) - case 3
UF(2)-trees - example
a
b
c
d
e
f
UF(2)-trees - example
a
b
c
d
e
f
UF(2)-trees - example
a
b
c
d
e
f
UF(2)-trees - example
a
b
c
d
e
f
UF(k) - case 1
Total number of sons  k
UF(k) - case 2
Total number of sons > k
UF(k) - case 3
Complexity = O(k)
= O(k+logkn)
IUF(k)-trees
Let k be an integer, 2  k  n. A tree T is called a
IUF(k)-tree , if:
•The root of T has at most k sons.
•Each node in T has either 0 or more than k grandsons.
IUF(k) trees - unbalanced
IUF(k) - linear size
IUF(k) - linear size
L - depth 0 (leaves)
M - depth 1
R - depth > 1
ML
#nodes  (k+1)R
L+M+R  (k+1)R
R  (L+M)/K  (L+M)/2  L
IUF(k) - case 1
Total number of sons  k
IUF(k) - case 1
Total number of sons  k
IUF(k) - case 2
Total number of sons > k
IUF(k) - case 2
Total number of sons > k
IUF(k) - case 3
IUF(k) - case 3
IUF(k) trees - balanced
It suffices to show than an IUF(k) tree has the same height as the
corresponding UK(k) tree that stores the same set.
We perform the sequence of UNION operations on the two data
structures in parallel.
•At each moment, the trees have the same height, and the roots
have the same number of sons.
•If we are in case j for the UF structure, we are in case j for the
IUF structure.
Case 3
Case 3
Summary
•Union: O(k) , Find: O(logkn)
•Optimality
•UF(k)-trees: balanced, linear.
•Three cases. Complexity: O(k+logkn)
•IUF(k)-trees. Linear, potentially unbalanced
•Similarity between data structures
References
•A Data Structure for the Union-Find Problem Having Good SingleOperation Complexity / Michiel H.M. Smid , 1989.
•Presentation: http://www.math.tau.ac.il/~ysh/seminar/uf.ppt
Related documents