cs 473 -algorithms i

21
CS 473 Lecture X 1 CS473-Algorithms I Lecture X Ackermann’s Function and Its Inverse

Upload: urvi

Post on 07-Feb-2016

44 views

Category:

Documents


0 download

DESCRIPTION

CS 473 -Algorithms I. Lecture X Ackermann ’ s Function and Its Inverse. if i = 0. if i > 0 and lg (i-1) n > 0. if i > 0 and. or. lg (i-1) n is undefined. undefined. Repeated Exponentiation Function g( i ). i. That is. The parameter i gives the height of the stack of 2 ’ s - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: CS 473 -Algorithms  I

CS 473 Lecture X 1

CS473-Algorithms I

Lecture X

Ackermann’s Function and Its Inverse

Page 2: CS 473 -Algorithms  I

CS 473 Lecture X 2

Repeated Exponentiation Function g(i)

12

1202

)()1(

2

1

iifiifiif

igig

That is 2

222)(

ig i

The parameter i gives the height of the stack of 2’s that make up the exponent

22222)4( g 4 6553622 2221642

Repeated Logarithm Function lg(i)n

)nlg(lg

nnlg )1i()i(

undefined

if i = 0

if i > 0 and lg(i-1)n > 0

if i > 0 and 0n or lg(i-1)n is undefined

The logarithm fn applied i time in succession starting with arg. n

Page 3: CS 473 -Algorithms  I

CS 473 Lecture X 3

Iterated Logarithm Function lg(*)n

lg* n = min { i 0 : lg(i)n 1 }lg* 2 = 1lg* 4 = lg*(22) = 2lg* 16 = lg*(24) = 3lg* 65536 = lg*(216) = 4lg* (265536) = 5

Since the number of atoms in the observable universe 1080 << 265536

We rarely encounter a value of n such that lg*n > 5

Page 4: CS 473 -Algorithms  I

CS 473 Lecture X 4

Computation of lg* 65536

465536lg )( Therefore

Iterated Logarithm Function

116)2lg(65536lg 16)1(

142lg16lg)65536lg(lg65536lg 4)2(

122lg4lg)65536lg(lg65536lg 2)2()3(

112lg)65536lg(lg65536lg )3()4(

Page 5: CS 473 -Algorithms  I

CS 473 Lecture X 5

The lg*n fn is essentially the inverse of repeated exponentiation

1)1n(g2)2lg())n(g(lg22

22)1( n n-1n

)2n(g2)2lg())1n(glg()))n(glg(lg())n(g(lg22

22)2( n-1 n-2

n-2

)3n(g2)2lg())2n(glg()))n(g(lg(lg))n(g(lg22

22)2()3( n-3

?))n(g(lg* where

2

222)n(g

n

Iterated Logarithm Function

Page 6: CS 473 -Algorithms  I

CS 473 Lecture X 6

.

.

.

2

2)i( 2))n(g(lg

n-i

.

.

.

122))n(g(lg2

2)n( n-n=0

112lg))n(g(lg )1n(

Therefore 1n)2(lg*))n(g(lg*2

2 n

Iterated Logarithm Function

Page 7: CS 473 -Algorithms  I

CS 473 Lecture X 7

Ackermann’s Function• Defined for integers i, j > 1 by

A(1, j) = 2j for j 1A(i, 1) = A(i – 1, 2) for i 2A(i, j) = A(i – 1, A(i, j - 1)) for i, j 2

j = 1 j = 4j = 3j = 2

i = 3

i = 2

i = 1 21 22 2423

Page 8: CS 473 -Algorithms  I

CS 473 Lecture X 8

Ackermann’s Function• Defined for integers i, j > 1 by

A(1, j) = 2j for j 1A(i, 1) = A(i – 1, 2) for i 2A(i, j) = A(i – 1, A(i, j - 1)) for i, j 2

j = 1 j = 4j = 3j = 2

i = 3

i = 2

i = 1 21 22 2423

22

Page 9: CS 473 -Algorithms  I

CS 473 Lecture X 9

Ackermann’s Function• Defined for integers i, j > 1 by

A(1, j) = 2j for j 1A(i, 1) = A(i – 1, 2) for i 2A(i, j) = A(i – 1, A(i, j - 1)) for i, j 2

j = 1 j = 4j = 3j = 2

i = 3

i = 2

i = 1 21 22 2423

22 222

Page 10: CS 473 -Algorithms  I

CS 473 Lecture X 10

Ackermann’s Function• Defined for integers i, j > 1 by

A(1, j) = 2j for j 1A(i, 1) = A(i – 1, 2) for i 2A(i, j) = A(i – 1, A(i, j - 1)) for i, j 2

j = 1 j = 4j = 3j = 2

i = 3

i = 2

i = 1 21 22 2423

22 222

222

Page 11: CS 473 -Algorithms  I

CS 473 Lecture X 11

Ackermann’s Function• Defined for integers i, j > 1 by

A(1, j) = 2j for j 1A(i, 1) = A(i – 1, 2) for i 2A(i, j) = A(i – 1, A(i, j - 1)) for i, j 2

j = 1 j = 4j = 3j = 2

i = 3

i = 2

i = 1 21 22 2423

22 222

222

2

22 16

2222 3

2

222224

Page 12: CS 473 -Algorithms  I

CS 473 Lecture X 12

Ackermann’s FunctionSecond Row

22222

222

2

22

22

22

2

2)2,1())3,2(,1()4,2(

2)2,1())2,3(,1()3,2(

2)2,1())1,2(,1()2,2(

2)2,1()1,2(

AAAA

AAAA

AAAA

AA

..

.2

22),2(

jA

2

3

4

j

1

Page 13: CS 473 -Algorithms  I

CS 473 Lecture X 13

Ackermann’s FunctionThird Row

22

22

222

22

22

222

22

2)2,2())3,3(,2()4,3(

2)2,2())2,3(,2()3,3(

22)2,2())1,3(,2()2,3(

2)2,2()1,3(

AAAA

AAAA

AAAA

AA222 16

16

2

22 16

2

22 16 2

22

2

22 16

∙∙∙∙

Page 14: CS 473 -Algorithms  I

CS 473 Lecture X 14

Ackermann’s FunctionThird Row

∙∙∙∙2

22),3(

jA

2

22

2

22

2

22 16

j-1 of thesefor j 2

• The first row, exponential in the column number j, is already rapidly growing• The second row, consists of the widely spaced subset of columns of the first row• The third row consists of even more widely spaced subset of columns

, …, of the second row which is even sparser subset of columns of the first row

,....,2,2,2222 222

222 222 2,2,2,2

2

22

1616

Page 15: CS 473 -Algorithms  I

CS 473 Lecture X 15

Explosive Growth of Ackermann’s Function

1

2

3

4

5

Row

ColumnS1 S2 S3 S4

Spacings

S1 S2

Page 16: CS 473 -Algorithms  I

CS 473 Lecture X 16

• The first row, exponential in the column number j, is already rapidly growing

• The second row, consists of the widely spaced subset of columns of the first row

• The third row consists of even more widely spaced subset of columns

, …, of the second row which is even sparser subset of columns of the first row

,....,2,2,2222 222

222 222 2,2,2,2

2

22

1616

Explosive Growth of Ackermann’s Function

Page 17: CS 473 -Algorithms  I

CS 473 Lecture X 17

Inverse of Ackermann’s Functionα(m, n) = min{ i 1 : A( i, ) > lg n } nm /

– Proceed in the -th column of the matrixstarting from the first row

– Until you encounter a value > lg n– Return the row index of that value

nm /

IN GENERALThe spacing between successive columns of row i-1 appearing in row i increases dramatically

with both the column number and the row number i

Explosive Growth of Ackermann’s Function

Page 18: CS 473 -Algorithms  I

CS 473 Lecture X 18

Inverse of Ackermann’s Function• This fn is not the inverse of Ackermann’s fn in true math sense• It captures the spirit of the inverse in its growth• The mysterious lg n threshold appears in order to be able to

prove the O(m α(m,n)) bound on the running time

Claim : for all practical purposes

– since

– Ackermann’s fn A(i, j) is strictly increasing with each argument

– for all since

4),( nma

1/ nm nm

)1,()/,( iAnmiA 1i 1/ nm

Page 19: CS 473 -Algorithms  I

CS 473 Lecture X 19

In particular,

But we also have A(4,1) = A(3,2) =

Hence, A(4,1) >> 1080 = Estimated no. of atoms in the universe

Thus, for all practical purposes

)1,4()/,4( AnmA 2

22 16

4),( nm

Inverse of Ackermann’s Function

O(mlg*n) bound is only slightly weaker than O(m α(m,n)) bound

52)2(lg*

4)2(lg*2lg*)K64(lg*222

22

2K64

216

,

so 5nlg* for all practical purposes

Page 20: CS 473 -Algorithms  I

CS 473 Lecture X 20

An Important Property of Inverse Ackermann’s FunctionFor a fixed value of n, as m increases

the function α(m,n) is monotonically decreasingProof : is monotonically increasing as m increasesThus, since n and hence lg n is fixed, the smallest row index i needed to bring above lg n is monotonically decreasing

n/m

)( n,m,iA

A(i1,c1) = First value in col. c1 > lg n

1 2 ….. n/mc 11 n/mc 22

i1

i2

12345...

1

2

1

2

mm

cc

1

A(i,c2) > A(i,c1) for all i

12 ii where

A(i2,c2) = First value in col. c2 > lg n

Page 21: CS 473 -Algorithms  I

CS 473 Lecture X 21

An Important Property of Inverse Ackermann’s Function

• This property corresponds to our intuition aboutdisjoint set forests with path compression

• We would expect the average FIND-PATH length to decreasedue to path compression

• If we perform m operations in time O(m α(m,n)) then, the average time per operation is O(α(m,n))

which is monotonically decreasing as m increases