146
© Raimund Seidel Path Compression and Making the Inverse Ackermann Function Appear Natural(ly) Raimund Seidel Universität des Saarlandes

Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Path Compression and Making the

Inverse Ackermann FunctionAppear Natural(ly)

Raimund Seidel

Universität des Saarlandes

Page 2: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Theorem:

Any sequence of m Union, Find operationsin a universe of n elements that uses linking by rank and path compressiontakes time at most

O( m·αααα(m,n) +n )

Bob Tarjan 1975

Page 3: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Theorem:

Any sequence of m Union, Find operationsin a universe of n elements that uses linking by rank and path compressiontakes time at most

O( m·αααα(m,n) +n )

Bob Tarjan 1975

where αααα(m,n) is the “Functional Inverse” of the Ackermann Function.

Page 4: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

What is this αααα(m,n) ??

Page 5: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

What is this αααα(m,n) ??

Why does this αααα(m,n)appear in the analysis ofpath compression ??

Page 6: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

What is this αααα(m,n) ??

Page 7: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Page 8: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Page 9: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

This definition of αααα(m,n)is not particularly enlightening.

Page 10: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Why does this αααα(m,n)appear in the analysis ofpath compression ??

Page 11: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Union Find with Path Compressions

Page 12: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Union Find with Path Compressions

Maintain partition of S = { 1,2,L,n}

under operations

1 2

5

9

84

3 6

7

Page 13: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Union Find with Path Compressions

Maintain partition of S = { 1,2,L,n}

under operations

1 2

5

9

84

3 6

7

Union( 2 , 4 )

1 2

5

9

84

3 6

7

Page 14: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Union Find with Path Compressions

Maintain partition of S = { 1,2,L,n}

under operations

1 2

5

9

84

3 6

7

Union( 2 , 4 )

1 2

5

9

84

3 6

7

Find( 3 ) = 6 (representative element)

Page 15: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Implementation

* forest FFFF of rooted trees with node set S* one tree for each group in current partition* root of tree is representative of the group

2 4 6 5 9

1 8 3

7

2 4 6 5 9

1 8 3

7

Page 16: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Implementation

* forest FFFF of rooted trees with node set S* one tree for each group in current partition* root of tree is representative of the group

2 4 6 5 9

1 8 3

7

2 4 6 5 9

1 8 3

7

Union( 2 , 4 )

4 6 5 9

2 8 3

1 7“Linking”

Page 17: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Implementation

* forest FFFF of rooted trees with node set S* one tree for each group in current partition* root of tree is representative of the group

2 4 6 5 9

1 8 3

7

2 4 6 5 9

1 8 3

7

Union( 2 , 4 )

4 6 5 9

2 8 3

1 7“Linking”

Find( x ) follow path from x to root “path follwoing”

Page 18: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Heuristic 1: “linking by rank”

• each node x carries integer rk(x)

• initially rk(x) = 0

• as soon as x is NOT a root, rk(x) stays unchanged

• for Union( x , y ) make node with smaller rankchild of the otherin case of tie, increment one of the

ranksx4 y7

x4 y4

y7x4

y5x4

Page 19: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Heuristic 2: Path compression

when performin a Find( x ) operation makeall nodes in the “findpath” children of the root

3

2 5 1

7 9 6

11 29

4

23 15

3

2 5 6 11 4 1

7 9 29 23 15

Find( 4 )

Page 20: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

sequence of Union and Find operation

Explicit cost model:

cost( op ) = # times some node gets a new parent

Time for Union(x , y) = O(1) = O(cost( Union(x,y) ))

Time for Find( x ) = O( # of nodes on findpath )

= O( 2 + cost( Find(x) ) )

Page 21: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

For analysis assume all Unions are performed first, but Find-paths are only followed (and compressed) to correct node.

Page 22: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

For analysis assume all Unions are performed first, but Find-paths are only followed (and compressed) to correct node.

Page 23: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

General path compression in forest FFFF

x

a

b

y

compress( x, y )

Page 24: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

General path compression in forest FFFF

x

a

b

y

xab

y

compress( x, y )

Page 25: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

General path compression in forest FFFF

x

a

b

y

xab

y

compress( x, y )

cost( compress( x,y ) ) = # of nodes that get a new parent

Page 26: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Problem formulation

FFFF forest on node set X

C sequence of compress operations on FFFF

|C| = # of true compress operations in C

cost( C ) = ∑( cost of individual operations )

How large can cost( C ) be at most,in terms of |X| and |C| ?

Page 27: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Idea:

For the analysis try “divide and conquer.”

Page 28: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Idea:

For the analysis try “divide and conquer.”

Question:

How do you “divide” ?

Page 29: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Dissection of a forest FFFF with node set X :

partition of X into “top part” Xtand “bottom part” Xb

so that top part Xt is “upwards closed”,

i.e. x∈Xt ⇒ every ancestor of x is in Xt also

Page 30: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Dissection of a forest FFFF with node set X :

partition of X into “top part” Xtand “bottom part” Xb

so that top part Xt is “upwards closed”,

i.e. x∈Xt ⇒ every ancestor of x is in Xt also

Page 31: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Dissection of a forest FFFF with node set X :

partition of X into “top part” Xtand “bottom part” Xb

so that top part Xt is “upwards closed”,

i.e. x∈Xt ⇒ every ancestor of x is in Xt also

Note: Xt, Xb dissection for FFFFF F F F ’ obtained from FFFF bysequence of path compressions

Xt, Xb isdissection for FFFF ’⇒

Page 32: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Main Lemma:C ... sequence of operations on FFFF with node set XXt, Xb dissection for FFFF inducing subforests FFFFt, FFFFb

Page 33: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Main Lemma:C ... sequence of operations on FFFF with node set XXt, Xb dissection for FFFF inducing subforests FFFFt, FFFFb

⇒ ∃ compression sequences Cb for FFFFb and Ct for FFFFtwith

cost( C ) � cost( Cb ) + cost( Ct ) + |Xb| + |Ct|

|Cb| + |Ct| � |C|

and

Page 34: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Proof: 1) How to get Cb and Ct from C:

Page 35: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Proof: 1) How to get Cb and Ct from C:

compression paths from C

y

x

y

xinto Ctcase 1:

Page 36: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Proof: 1) How to get Cb and Ct from C:

compression paths from C

y

x

y

x

y

x

y

x

into Ct

into Cb

case 1:

case 2:

Page 37: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Proof: 1) How to get Cb and Ct from C:

compression paths from C

y

x

y

x

y

x’

x

y

x

y

x

y

x’

∞∞∞∞

x

into Ct

into Cb

into Ct

into Cb

case 1:

case 2:

case 3:

Page 38: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

compress( x, ∞∞∞∞ )

“rootpath compress”

X

x A

a B

b C

c

C

c

B

b

A

a

X

x

Page 39: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

compress( x, ∞∞∞∞ )

cost( compress( x, ∞∞∞∞ ) ) = # of nodes that get a new parent

= 0

“rootpath compress”

X

x A

a B

b C

c

C

c

B

b

A

a

X

x

Page 40: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Proof:

compression paths from C

y

x

y

x

y

x’

x

y

x

y

x

y

x’

∞∞∞∞

x

into Ct

into Cb

into Ct

into Cb

case 1:

case 2:

case 3:

|Cb| + |Ct| � |C|

Page 41: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

cost( C ) � cost( Cb ) + cost( Ct ) + |Xb| + |Ct|

Page 42: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

cost( C ) � cost( Cb ) + cost( Ct ) + |Xb| + |Ct|

cost( C )

Page 43: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

cost( C ) � cost( Cb ) + cost( Ct ) + |Xb| + |Ct|

green node gets new green parent: accounted by cost(Ct)

cost( C )

Page 44: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

cost( C ) � cost( Cb ) + cost( Ct ) + |Xb| + |Ct|

green node gets new green parent: accounted by cost(Ct)

brown node gets new brown parent: accounted by cost(Cb)

cost( C )

Page 45: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

cost( C ) � cost( Cb ) + cost( Ct ) + |Xb| + |Ct|

green node gets new green parent: accounted by cost(Ct)

brown node gets new brown parent: accounted by cost(Cb)

brown node gets new green parent: accounted by |Xb|for the first time

cost( C )

Page 46: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

cost( C ) � cost( Cb ) + cost( Ct ) + |Xb| + |Ct|

green node gets new green parent: accounted by cost(Ct)

brown node gets new brown parent: accounted by cost(Cb)

brown node gets new green parent: accounted by |Xb|for the first time - #roots( FFFFb )

cost( C )

Page 47: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

cost(C) � cost(Cb) + cost(Ct) + |Xb| - #roots(FFFFb) + |Ct|

green node gets new green parent: accounted by cost(Ct)

brown node gets new brown parent: accounted by cost(Cb)

brown node gets new green parent: accounted by |Xb|for the first time - #roots( FFFFb )

cost( C )

Page 48: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

cost(C) � cost(Cb) + cost(Ct) + |Xb| - #roots(FFFFb) + |Ct|

green node gets new green parent: accounted by cost(Ct)

brown node gets new brown parent: accounted by cost(Cb)

brown node gets new green parent: accounted by |Xb|for the first time - #roots( FFFFb )

brown node gets new green parent: accounted by |Ct|again

cost( C )

Page 49: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Main Lemma’:C ... sequence of operations on FFFF with node set XXt, Xb dissection for FFFF inducing subforests FFFFt, FFFFb

⇒ ∃ compression sequences Cb for FFFFb and Ct for FFFFtwith

cost( C ) � cost( Cb ) + cost( Ct )+ |Xb| - #roots(FFFFb) + |Ct|

|Cb| + |Ct| � |C|

and

Page 50: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

f(m,n) ... maximum cost of any compressionsequence C with |C|=m in an arbitraryforest with n nodes.

Claim: f(m,n) � (m+n)·log2n

Page 51: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Claim: f(m,n) � (m+n)·log2n

Page 52: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Claim: f(m,n) � (m+n)·log2n

Proof:

Xforest FFFF|X|=n

C compression sequence |C|=m

Page 53: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Claim: f(m,n) � (m+n)·log2n

Proof:

XXb

Xtforest FFFF|X|=n

FFFFb

FFFFt |Xt|=|Xb|=n/2

C compression sequence |C|=m

Page 54: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Claim: f(m,n) � (m+n)·log2n

Proof:

XXb

Xtforest FFFF|X|=n

FFFFb

FFFFt |Xt|=|Xb|=n/2

C compression sequence |C|=m

Main Lemma ⇒ ∃ Ct, Cb |Cb|+|Ct| � |C|

cost( C ) � cost( Cb ) + cost( Ct ) + |Xb| + |Ct|

mb + mt � m

Page 55: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Claim: f(m,n) � (m+n)·log2n

Proof:

XXb

Xtforest FFFF|X|=n

FFFFb

FFFFt |Xt|=|Xb|=n/2

C compression sequence |C|=m

Main Lemma ⇒ ∃ Ct, Cb |Cb|+|Ct| � |C|

cost( C ) � cost( Cb ) + cost( Ct ) + |Xb| + |Ct|

mb + mt � m

Induction: � (mb+n/2)log n/2 + (mt+n/2)log n/2 + n/2 + mt

Page 56: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Claim: f(m,n) � (m+n)·log2n

Proof:

XXb

Xtforest FFFF|X|=n

FFFFb

FFFFt |Xt|=|Xb|=n/2

C compression sequence |C|=m

Main Lemma ⇒ ∃ Ct, Cb |Cb|+|Ct| � |C|

cost( C ) � cost( Cb ) + cost( Ct ) + |Xb| + |Ct|

mb + mt � m

Induction: � (mb+n/2)log n/2 + (mt+n/2)log n/2 + n/2 + mt

� (mb+mt+n/2+n/2)log n/2 + n + m

Page 57: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Claim: f(m,n) � (m+n)·log2n

Proof:

XXb

Xtforest FFFF|X|=n

FFFFb

FFFFt |Xt|=|Xb|=n/2

C compression sequence |C|=m

Main Lemma ⇒ ∃ Ct, Cb |Cb|+|Ct| � |C|

cost( C ) � cost( Cb ) + cost( Ct ) + |Xb| + |Ct|

mb + mt � m

Induction: � (mb+n/2)log n/2 + (mt+n/2)log n/2 + n/2 + mt

� (mb+mt+n/2+n/2)log n/2 + n + m

� (m+n)·log2n/2 + (m+n) = (m+n)·log2n

Page 58: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Corollary:Any sequence of m Union, Find operationsin a universe of n elements that usesarbitrary linking and path compressiontakes time at most

O( (m+n)·log n)

Page 59: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Corollary:Any sequence of m Union, Find operationsin a universe of n elements that usesarbitrary linking and path compressiontakes time at most

O( (m+n)·log n)

By choosing a dissection that is “unbalanced”in relation to m/n one can prove a betterbound of

O( (m+n)·log⌈m/n⌉+1 n)

Page 60: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Corollary:Any sequence of m Union, Find operationsin a universe of n elements that usesarbitrary linking and path compressiontakes time at most

O( (m+n)·log n)

By choosing a dissection that is “unbalanced”in relation to m/n one can prove a betterbound of

O( (m+n)·log⌈m/n⌉+1 n)

Proof: exercise

Page 61: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Path compression and union by rank

Page 62: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

f : N → R Brief digression

Page 63: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

0 if n � 1

1 + f*( f(n) ) if n > 1f*(n) =

f : N → R Brief digression

Page 64: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

0 if n � 1

1 + f*( f(n) ) if n > 1f*(n) =

f*(n) = min { k | f(f( LL f(n)L) � 1 }

k times

f : N → R Brief digression

Page 65: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

0 if n � 1

1 + f*( f(n) ) if n > 1f*(n) =

f*(n) = min { k | f(f( LL f(n)L) � 1 }

k times

Properties: f a “nice” compaction, i.e. f(n)<n-1⇒ f* a “nice” compaction andf* “much smaller” than f

f : N → R Brief digression

Page 66: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Examples for f* :

f(n) f*(n)

n-1 n-1

n-2 n/2

n-c n/c

n/2 log2n

n/c logcn

n log log n

log n log*n

Brief digression

Page 67: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Path compression and union by rank

Def: FFFF forest, x node in FFFFr(x) = height of subtree rooted at x

( r(leaf) = 0 )

FFFF is a rank forest, if

for every node xfor every i with 0�i<r(x),

there is a child yi of x with r(yi)=i .

Page 68: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Path compression and union by rank

Def: FFFF forest, x node in FFFFr(x) = height of subtree rooted at x

( r(leaf) = 0 )

FFFF is a rank forest, if

for every node xfor every i with 0�i<r(x),

there is a child yi of x with r(yi)=i .

Note: Union by rank produces rank forests !

Page 69: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Path compression and union by rank

Def: FFFF forest, x node in FFFFr(x) = height of subtree rooted at x

( r(leaf) = 0 )

FFFF is a rank forest, if

for every node xfor every i with 0�i<r(x),

there is a child yi of x with r(yi)=i .

Note: Union by rank produces rank forests !

Lemma: r(x)=r ⇒ x has at least r children.

Page 70: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Path compression and union by rank

Def: FFFF forest, x node in FFFFr(x) = height of subtree rooted at x

( r(leaf) = 0 )

FFFF is a rank forest, if

for every node xfor every i with 0�i<r(x),

there is a child yi of x with r(yi)=i .

Note: Union by rank produces rank forests !

Lemma: r(x)=r ⇒ x has at least r childrenand at least 2r descendants.

Page 71: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Inheritance Lemma:

FFFF rank forest with maximum rank r and node set X

s∈N: X>s = { x∈X | r(x)>s } FFFF>s

X�s = { x∈X | r(x)�s } FFFF�sinduced forests

Page 72: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Inheritance Lemma:

FFFF rank forest with maximum rank r and node set X

s∈N: X>s = { x∈X | r(x)>s } FFFF>s

X�s = { x∈X | r(x)�s } FFFF�sinduced forests

i) X�s , X>s is a dissection for FFFF

ii) FFFF�s is a rank forest with maximumrank � s

iii) FFFF>s is a rank forest with maximumrank � r-s-1

Page 73: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Inheritance Lemma:

FFFF rank forest with maximum rank r and node set X

s∈N: X>s = { x∈X | r(x)>s } FFFF>s

X�s = { x∈X | r(x)�s } FFFF�sinduced forests

FFFFt

FFFFb

i) X�s , X>s is a dissection for FFFF

ii) FFFF�s is a rank forest with maximumrank � s

iii) FFFF>s is a rank forest with maximumrank � r-s-1

s

r-s-1

Page 74: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Inheritance Lemma:

FFFF rank forest with maximum rank r and node set X

s∈N: X>s = { x∈X | r(x)>s } FFFF>s

X�s = { x∈X | r(x)�s } FFFF�sinduced forests

FFFFt

FFFFb

i) X�s , X>s is a dissection for FFFF

ii) FFFF�s is a rank forest with maximumrank � s

iii) FFFF>s is a rank forest with maximumrank � r-s-1

s

r-s-1

Proofs: exercise

Page 75: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

f(m,n,r) = maximum cost of any compressionsequence C, with |C|=m, in rankforest FFFF with n nodes andmaximum rank r.

Page 76: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

f(m,n,r) = maximum cost of any compressionsequence C, with |C|=m, in rankforest FFFF with n nodes andmaximum rank r.

Trivial bounds:

f(m,n,r) � (r-1)·n

f(m,n,r) � (r-1)·m

Page 77: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

f(m,n,r) = maximum cost of any compressionsequence C, with |C|=m, in rankforest FFFF with n nodes andmaximum rank r.

Trivial bounds:

f(m,n,r) � (r-1)·n

f(m,n,r) � (r-1)·m

f(m,n,r) � m + (r-2)·n

Page 78: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

FFFFt

FFFFb

rs |X� s| = nb = n-nt |Cb| = mb

r-s-1 < r |X>s| = nt |Ct| = mt

cost( C ) � cost( Ct ) + cost( Cb ) + |Xb| - #rts(FFFFb) + |Ct|

Page 79: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

FFFFt

FFFFb

rs |X� s| = nb = n-nt |Cb| = mb

r-s-1 < r |X>s| = nt |Ct| = mt

cost( C ) � cost( Ct ) + cost( Cb ) + |Xb| - #rts(FFFFb) + |Ct|

� f(mt,nt,r-s-1) +

Page 80: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

FFFFt

FFFFb

rs |X� s| = nb = n-nt |Cb| = mb

r-s-1 < r |X>s| = nt |Ct| = mt

cost( C ) � cost( Ct ) + cost( Cb ) + |Xb| - #rts(FFFFb) + |Ct|

� f(mt,nt,r-s-1) + f(mb,nb,s) +

Page 81: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

FFFFt

FFFFb

rs |X� s| = nb = n-nt |Cb| = mb

r-s-1 < r |X>s| = nt |Ct| = mt

cost( C ) � cost( Ct ) + cost( Cb ) + |Xb| - #rts(FFFFb) + |Ct|

� f(mt,nt,r-s-1) + f(mb,nb,s) + n-nt –

Page 82: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

FFFFt

FFFFb

rs |X� s| = nb = n-nt |Cb| = mb

r-s-1 < r |X>s| = nt |Ct| = mt

cost( C ) � cost( Ct ) + cost( Cb ) + |Xb| - #rts(FFFFb) + |Ct|

� f(mt,nt,r-s-1) + f(mb,nb,s) + n-nt – (s+1)·nt +

Page 83: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

FFFFt

FFFFb

rs |X� s| = nb = n-nt |Cb| = mb

r-s-1 < r |X>s| = nt |Ct| = mt

cost( C ) � cost( Ct ) + cost( Cb ) + |Xb| - #rts(FFFFb) + |Ct|

� f(mt,nt,r-s-1) + f(mb,nb,s) + n-nt – (s+1)·nt +

Each node in FFFFt has at least s+1 children in FFFFb , and they must all be different roots of FFFFb .

Page 84: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

FFFFt

FFFFb

rs |X� s| = nb = n-nt |Cb| = mb

r-s-1 < r |X>s| = nt |Ct| = mt

cost( C ) � cost( Ct ) + cost( Cb ) + |Xb| - #rts(FFFFb) + |Ct|

� f(mt,nt,r-s-1) + f(mb,nb,s) + n-nt – (s+1)·nt + mt

Each node in FFFFt has at least s+1 children in FFFFb , and they must all be different roots of FFFFb .

Page 85: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

FFFFt

FFFFb

rs |X� s| = nb = n-nt |Cb| = mb

r-s-1 < r |X>s| = nt |Ct| = mt

cost( C ) � cost( Ct ) + cost( Cb ) + |Xb| - #rts(FFFFb) + |Ct|

� f(mt,nt,r-s-1) + f(mb,nb,s) + n-nt – (s+1)·nt + mt

Each node in FFFFt has at least s+1 children in FFFFb , and they must all be different roots of FFFFb .

f(m,n,r) � f(mt,nt,r-s-1) + f(mb,nb,s) + n – (s+2)·nt + mt

Page 86: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

f(m,n,r) � f(mt,nt,r-s-1) + f(mb,nb,s) + n – (s+2)·nt + mt

nt + nb = n mt + mb � m

0� s < r

Page 87: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

f(m,n,r) � f(mt,nt,r-s-1) + f(mb,nb,s) + n – (s+2)·nt + mt

nt + nb = n mt + mb � m

0� s < r

Assume: f(M,N,R) � k·M + N·g(R)

Page 88: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

f(m,n,r) � f(mt,nt,r-s-1) + f(mb,nb,s) + n – (s+2)·nt + mt

nt + nb = n mt + mb � m

0� s < r

f(m,n,r) � k·mt + nt·g(r-s-1) + f(mb,nb,s) + n – (s+2)·nt + mt

� k·mt + nt·g(r) + f(mb,nb,s) + n – s·nt + mt

Assume: f(M,N,R) � k·M + N·g(R)

Page 89: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

f(m,n,r) � f(mt,nt,r-s-1) + f(mb,nb,s) + n – (s+2)·nt + mt

nt + nb = n mt + mb � m

0� s < r

f(m,n,r) � k·mt + nt·g(r-s-1) + f(mb,nb,s) + n – (s+2)·nt + mt

� k·mt + nt·g(r) + f(mb,nb,s) + n – s·nt + mt

choose s = g(r)

Assume: f(M,N,R) � k·M + N·g(R)

Page 90: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

f(m,n,r) � f(mt,nt,r-s-1) + f(mb,nb,s) + n – (s+2)·nt + mt

nt + nb = n mt + mb � m

0� s < r

f(m,n,r) � k·mt + nt·g(r-s-1) + f(mb,nb,s) + n – (s+2)·nt + mt

� k·mt + nt·g(r) + f(mb,nb,s) + n – s·nt + mt

choose s = g(r)

f(m,n,r) � (k+1)·mt + f(mb,nb,s) + n

� (k+1)·mt + f(mb,n,s) + n

Assume: f(M,N,R) � k·M + N·g(R)

Page 91: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

s = g(r)

f(m,n,r) � (k+1)·mt + f(mb,n,s) + n

Page 92: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

s = g(r)

f(m,n,r) � (k+1)·mt + f(mb,n,s) + n -(k+1)·(mb+mt)

Page 93: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

s = g(r)

f(m,n,r) � (k+1)·mt + f(mb,n,s) + n -(k+1)·(mb+mt)

m

Page 94: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

s = g(r)

f(m,n,r) � (k+1)·mt + f(mb,n,s) + n -(k+1)·(mb+mt)

f(m,n,r) – (k+1)·m � f(mb,n,s) – (k+1)·mb + n

m

Page 95: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

s = g(r)

f(m,n,r) � (k+1)·mt + f(mb,n,s) + n -(k+1)·(mb+mt)

f(m,n,r) – (k+1)·m � f(mb,n,s) – (k+1)·mb + n

φ(m,n,r) � φ(mb,n,g(r)) + n

m

Page 96: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

s = g(r)

f(m,n,r) � (k+1)·mt + f(mb,n,s) + n -(k+1)·(mb+mt)

f(m,n,r) – (k+1)·m � f(mb,n,s) – (k+1)·mb + n

φ(m,n,r) � φ(mb,n,g(r)) + n

m

� (φ(mbb,n,g(g(r))) + n) + n

Page 97: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

s = g(r)

f(m,n,r) � (k+1)·mt + f(mb,n,s) + n -(k+1)·(mb+mt)

f(m,n,r) – (k+1)·m � f(mb,n,s) – (k+1)·mb + n

φ(m,n,r) � φ(mb,n,g(r)) + n

m

� (φ(mbb,n,g(g(r))) + n) + n

� ((φ(mbbb,n,g(g(g(r)))) + n) + n) + n

Page 98: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

s = g(r)

f(m,n,r) � (k+1)·mt + f(mb,n,s) + n -(k+1)·(mb+mt)

f(m,n,r) – (k+1)·m � f(mb,n,s) – (k+1)·mb + n

φ(m,n,r) � φ(mb,n,g(r)) + n

m

� (φ(mbb,n,g(g(r))) + n) + n

� ((φ(mbbb,n,g(g(g(r)))) + n) + n) + n

φ(m,n,r) � n · g*(r)

Page 99: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

s = g(r)

f(m,n,r) � (k+1)·mt + f(mb,n,s) + n -(k+1)·(mb+mt)

f(m,n,r) – (k+1)·m � f(mb,n,s) – (k+1)·mb + n

φ(m,n,r) � φ(mb,n,g(r)) + n

m

� (φ(mbb,n,g(g(r))) + n) + n

� ((φ(mbbb,n,g(g(g(r)))) + n) + n) + n

φ(m,n,r) � n · g*(r)

f(m,n,r) � (k+1)· m + n · g*(r)

Page 100: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Shifting Lemma:

If f(m,n,r) � k·m + n·g(r)

then also f(m,n,r) � (k+1)·m + n·g*(r)

Page 101: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

If f(m,n,r) � k·m + n·g(r)

then also f(m,n,r) � (k+i)·m + n·g**...*(r)

for any i ≥ 0

Shifting Lemma:

If f(m,n,r) � k·m + n·g(r)

then also f(m,n,r) � (k+1)·m + n·g*(r)

Shifting Corollary:

i

Page 102: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

If f(m,n,r) � k·m + n·g(r)

then also f(m,n,r) � (k+i)·m + n·g**...*(r)

for any i ≥ 0

i

Page 103: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

If f(m,n,r) � k·m + n·g(r)

then also f(m,n,r) � (k+i)·m + n·g**...*(r)

for any i ≥ 0

Trivial bound: f(m,n,r) � n·(r-1)

i

Page 104: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

If f(m,n,r) � k·m + n·g(r)

then also f(m,n,r) � (k+i)·m + n·g**...*(r)

for any i ≥ 0

Trivial bound: f(m,n,r) � n·(r-1)

= 0·m + n·(r-1)

i

Page 105: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

If f(m,n,r) � k·m + n·g(r)

then also f(m,n,r) � (k+i)·m + n·g**...*(r)

for any i ≥ 0

Trivial bound: f(m,n,r) � n·(r-1)

= 0·m + n·(r-1)

g(r) = r-1

g*(r) = r-1

i

Page 106: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

If f(m,n,r) � k·m + n·g(r)

then also f(m,n,r) � (k+i)·m + n·g**...*(r)

for any i ≥ 0

Trivial bound: f(m,n,r) � m + n·(r-2)

i

Page 107: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

If f(m,n,r) � k·m + n·g(r)

then also f(m,n,r) � (k+i)·m + n·g**...*(r)

for any i ≥ 0

Trivial bound: f(m,n,r) � m + n·(r-2)

= 1·m + n·(r-2)

i

Page 108: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

If f(m,n,r) � k·m + n·g(r)

then also f(m,n,r) � (k+i)·m + n·g**...*(r)

for any i ≥ 0

Trivial bound: f(m,n,r) � m + n·(r-2)

= 1·m + n·(r-2)

g(r) = r-2

i

Page 109: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

If f(m,n,r) � k·m + n·g(r)

then also f(m,n,r) � (k+i)·m + n·g**...*(r)

for any i ≥ 0

Trivial bound: f(m,n,r) � m + n·(r-2)

= 1·m + n·(r-2)

g(r) = r-2

g*(r)= r/2

i

Page 110: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

If f(m,n,r) � k·m + n·g(r)

then also f(m,n,r) � (k+i)·m + n·g**...*(r)

for any i ≥ 0

Trivial bound: f(m,n,r) � m + n·(r-2)

= 1·m + n·(r-2)

g(r) = r-2

g*(r)= r/2 f(m,n,r) � 2·m + n·(r/2)

i

Page 111: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

If f(m,n,r) � k·m + n·g(r)

then also f(m,n,r) � (k+i)·m + n·g**...*(r)

for any i ≥ 0

Trivial bound: f(m,n,r) � m + n·(r-2)

= 1·m + n·(r-2)

g(r) = r-2

g*(r)= r/2 f(m,n,r) � 2·m + n·(r/2)

g**(r) = log r

i

Page 112: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

If f(m,n,r) � k·m + n·g(r)

then also f(m,n,r) � (k+i)·m + n·g**...*(r)

for any i ≥ 0

Trivial bound: f(m,n,r) � m + n·(r-2)

= 1·m + n·(r-2)

g(r) = r-2

g*(r)= r/2 f(m,n,r) � 2·m + n·(r/2)

g**(r) = log r f(m,n,r) � 3·m + n·log r

i

Page 113: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

If f(m,n,r) � k·m + n·g(r)

then also f(m,n,r) � (k+i)·m + n·g**...*(r)

for any i ≥ 0

i

Page 114: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

If f(m,n,r) � k·m + n·g(r)

then also f(m,n,r) � (k+i)·m + n·g**...*(r)

for any i ≥ 0

We know bound: f(m,n,r) � 3·m + n·log r

i

Page 115: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Therefore for any i≥ 0 :

f(m,n,r) � (3+i)·m + n·log**...*(r)

If f(m,n,r) � k·m + n·g(r)

then also f(m,n,r) � (k+i)·m + n·g**...*(r)

for any i ≥ 0

We know bound: f(m,n,r) � 3·m + n·log r

i

i

Page 116: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

For any i≥ 0 : f(m,n,r) � (3+i)·m + n·log**...*(r)

i

Page 117: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

For any i≥ 0 : f(m,n,r) � (3+i)·m + n·log**...*(r)

Choice of i :

i

Page 118: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

For any i≥ 0 : f(m,n,r) � (3+i)·m + n·log**...*(r)

Choice of i :i

Define αααα(r) = min{ i | log**...*(r) � i }

i

Page 119: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

For any i≥ 0 : f(m,n,r) � (3+i)·m + n·log**...*(r)

i

Choice of i :

Define αααα(r) = min{ i | log**...*(r) � i }

i

Here is your definition of the Inverse Ackermann Function !!

Page 120: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

For any i≥ 0 : f(m,n,r) � (3+i)·m + n·log**...*(r)

i

Choice of i :

Define αααα(r) = min{ i | log**...*(r) � i }

f(m,n,r) � (m+n)(3+αααα(r))

i

Page 121: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

For any i≥ 0 : f(m,n,r) � (3+i)·m + n·log**...*(r)

i

Choice of i :

Define αααα(r) = min{ i | log**...*(r) � i }

f(m,n,r) � (m+n)(3+αααα(r))

� (m+n)(3+αααα(log n))

i

Page 122: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Choice of i :

For any i≥ 0 : f(m,n,r) � (3+i)·m + n·log**...*(r)

i

Page 123: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

For any i≥ 0 : f(m,n,r) � (3+i)·m + n·log**...*(r)

Choice of i :i

For t≥ 1 define ααααt(r) = min{ i | log**...*(r) � t }

i

Page 124: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

For any i≥ 0 : f(m,n,r) � (3+i)·m + n·log**...*(r)

Choice of i :i

For t≥ 1 define ααααt(r) = min{ i | log**...*(r) � t }

i

Here is a parametrized definition of the Inverse Ackermann Function !!

Page 125: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

For any i≥ 0 : f(m,n,r) � (3+i)·m + n·log**...*(r)

Choice of i :i

For t≥ 1 define ααααt(r) = min{ i | log**...*(r) � t }

i

f(m,n,r) � (3+ααααt(r))·m + n·t

Page 126: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

For any i≥ 0 : f(m,n,r) � (3+i)·m + n·log**...*(r)

Choice of i :i

For t≥ 1 define ααααt(r) = min{ i | log**...*(r) � t }

i

f(m,n,r) � (3+ααααt(r))·m + n·t

choose t = 1+m/n

Page 127: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

For any i≥ 0 : f(m,n,r) � (3+i)·m + n·log**...*(r)

Choice of i :i

For t≥ 1 define ααααt(r) = min{ i | log**...*(r) � t }

i

f(m,n,r) � (3+ααααt(r))·m + n·t

choose t = 1+m/n

f(m,n,r) � (4+αααα1+m/n(r))·m + n

Page 128: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

For any i≥ 0 : f(m,n,r) � (3+i)·m + n·log**...*(r)

Choice of i :i

For t≥ 1 define ααααt(r) = min{ i | log**...*(r) � t }

i

f(m,n,r) � (3+ααααt(r))·m + n·t

choose t = 1+m/n

f(m,n,r) � (4+αααα1+m/n(r))·m + n

� (4+αααα1+m/n(log n))·m + n

Page 129: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Theorem:

Any sequence of m Union, Find operationsin a universe of n elements that uses linking by rank and path compressiontakes time at most

O( m·αααα(m,n) +n )

Bob Tarjan 1975

Page 130: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Theorem:

Any sequence of m Union, Find operationsin a universe of n elements that uses linking by rank and path compressiontakes time at most

O( m·αααα(m,n) +n )

Bob Tarjan 1975

f(m,n,r) � (4+αααα1+m/n(log n))·m + n

Page 131: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Theorem:

Any sequence of m Union, Find operationsin a universe of n elements that uses linking by rank and path compressiontakes time at most

O( m·αααα(m,n) +n )

Bob Tarjan 1975

f(m,n,r) � (4+αααα1+m/n(log n))·m + n

αααα(m,n) = αααα1+m/n(log n)

Page 132: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Shifting Lemma:

If f(m,n,r) � k·m + n·g(r)

then also f(m,n,r) � (k+1)·m + n·g*(r)

If f(m,n,r) � k·m + n·g(r)

then also f(m,n,r) � (k+i)·m + n·g**...*(r)

for any i ≥ 0

Shifting Corollary:

i

Definition of αααα: i

αααα(r) = min{ i | log**...*(r) � i }

What to remember:

Page 133: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Odds and Ends

Page 134: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Odds and Ends

We used f(m,n,r) � 1·m + n·(r-2)

Page 135: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Odds and Ends

We used f(m,n,r) � 1·m + n·(r-2) to get

for any i≥ 0 : f(m,n,r) � (3+i)·m + n·log**...*(r)

i

Page 136: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Odds and Ends

We used f(m,n,r) � 1·m + n·(r-2) to get

Actually f(m,n,r) � 1·m + n·log r

for any i≥ 0 : f(m,n,r) � (3+i)·m + n·log**...*(r)

i

Page 137: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Odds and Ends

We used f(m,n,r) � 1·m + n·(r-2) to get

Actually f(m,n,r) � 1·m + n·log r(Exercise)

for any i≥ 0 : f(m,n,r) � (3+i)·m + n·log**...*(r)

i

Page 138: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Odds and Ends

We used f(m,n,r) � 1·m + n·(r-2) to get

for any i≥ 0 : f(m,n,r) � (1+i)·m + n·log**...*(r)

i

Actually f(m,n,r) � 1·m + n·log r

and therefore(Exercise)

for any i≥ 0 : f(m,n,r) � (3+i)·m + n·log**...*(r)

i

Page 139: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Odds and Ends

For any i≥ 0 : f(m,n,r) � i·m + n·log**...*(r)

i

Actually f(m,n,r) � 1·m + n·log* r

and therefore

(difficultExercise)

Page 140: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Odds and Ends

f(m,n,r) for small values of r

Page 141: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Odds and Ends

f(m,n,0) = 0 f(m,n,1) = 0 f(m,n,2) � m

f(m,n,r) for small values of r

Page 142: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Odds and Ends

f(m,n,0) = 0 f(m,n,1) = 0 f(m,n,2) � m

f(m,n,r) � m + n for r� 8, i.e. for n<512

f(m,n,r) for small values of r

Page 143: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Odds and Ends

f(m,n,0) = 0 f(m,n,1) = 0 f(m,n,2) � m

f(m,n,r) � m + n for r� 8, i.e. for n<512

f(m,n,r) � m + 2n for r� 202, i.e. for n<2203

f(m,n,r) for small values of r

Page 144: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Odds and Ends

f(m,n,0) = 0 f(m,n,1) = 0 f(m,n,2) � m

f(m,n,r) � m + n for r� 8, i.e. for n<512

f(m,n,r) � m + 2n for r� 202, i.e. for n<2203

f(m,n,r) for small values of r

(difficult exercises)

Page 145: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Similar proof for O( m·αααα(m,n) + n ) bound also works for

* linking by weight and path compression

* linking by rank and generalized pathcompaction

Odds and Ends

Page 146: Path Compression and Making the InverseAckermann Function …€¦ · © Raimund Seidel Theorem: Any sequence of mUnion, Find operations in a universe of n elements that uses linking

© Raimund Seidel

Similar proof for O( m·αααα(m,n) + n ) bound also works for

* linking by weight and path compression

* linking by rank and generalized pathcompaction

Odds and Ends

Open problem:

simple top-down approach for provinglower bounds