41
Lecture overview ingle operation time complexity revious results ptimality proof F(k)-trees perations and complexity UF(k)-trees roperties and complexity

Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

Embed Size (px)

Citation preview

Page 1: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

Lecture overview•Single operation time complexity

•Previous results

•Optimality proof

•UF(k)-trees

•Operations and complexity

•IUF(k)-trees

•Properties and complexity

Page 2: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

Single operation complexityA 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)

Page 3: 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

)loglog

log(

logloglogloglog

log

)loglog

loglog(

log

log

loglog

loglog

log

n

nO

nn

n

nnn

k

nn

n

nk

k

Union: O(k)

Find: O(logkn)

Page 4: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

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

)logloglog

log(

nk

n

Corollary: There is always either a UNION or a FIND operation that takes

)loglog

log(

n

n

Page 5: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

Optimal data structure

n

n

nn

n

nnnn

nk

n

n

nk

loglog2

log

logloglogloglog2

log

loglog)loglog

loglog(

log

logloglog

log

loglog

log

Page 6: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

Optimal data structure

kn

nn

kn

n

k

n

knk

knkk

nk

nk

k logloglog

loglog

1

)loglog(log

log

log)1(

log

)loglog(loglog)1(

logloglogloglog

logloglog

0,)(log

Page 7: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

UF(k)-treesLet 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.

Page 8: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

UF(k)-tree structurename

sons

number of sons

height

leaf

Page 9: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

UK(k)-tree structureElements are stored at the leaves

a b c d e f g h

To FIND an element, climb to the root

Page 10: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

UK(k)-tree structure

a b c d e f

Initially all trees are of size 2.

Page 11: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

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)

Page 12: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

UF(k)-trees - linear

Page 13: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

UF(k)-trees - linear

Page 14: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

UF(k) - case 1

Total number of sons k

Page 15: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

UF(k) - case 1

Total number of sons k

Page 16: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

UF(k) - case 2

Total number of sons > k

Page 17: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

UF(k) - case 2

Total number of sons > k

Page 18: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

UF(k) - case 3

Page 19: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

UF(k) - case 3

Page 20: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

UF(2)-trees - example

a b c d e f

Page 21: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

UF(2)-trees - example

a b c d e f

Page 22: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

UF(2)-trees - example

a b c d e f

Page 23: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

UF(2)-trees - example

a b c d e f

Page 24: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

UF(k) - case 1

Total number of sons k

Page 25: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

UF(k) - case 2

Total number of sons > k

Page 26: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

UF(k) - case 3

Complexity = O(k) = O(k+logkn)

Page 27: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

IUF(k)-treesLet 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.

Page 28: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

IUF(k) trees - unbalanced

Page 29: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

IUF(k) - linear size

Page 30: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

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

Page 31: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

IUF(k) - case 1

Total number of sons k

Page 32: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

IUF(k) - case 1

Total number of sons k

Page 33: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

IUF(k) - case 2

Total number of sons > k

Page 34: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

IUF(k) - case 2

Total number of sons > k

Page 35: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

IUF(k) - case 3

Page 36: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

IUF(k) - case 3

Page 37: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

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.

Page 38: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

Case 3

Page 39: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

Case 3

Page 40: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

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

Page 41: Lecture overview Single operation time complexity Previous results Optimality proof UF(k)-trees Operations and complexity IUF(k)-trees Properties and complexity

References

•A Data Structure for the Union-Find Problem Having Good Single-Operation Complexity / Michiel H.M. Smid , 1989.

•Presentation: http://www.math.tau.ac.il/~ysh/seminar/uf.ppt