explore space complexity - tausafra/complexity/space.pdf · complexity 18 ©d.moshkovits (a,b,c)=is...

35
1

Upload: others

Post on 21-Jul-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

1

Page 3: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

3

nSPACEL log

nNSPACENL log

TM space-by decided | ticdeterminisntOLLntSPACE

TM non space- by decided | ticdeterminisntOLLntNSPACE

k

knSPACEPSPACE

Page 4: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

4

Page 5: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

5

?

Page 6: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

6

Page 8: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

8

Page 9: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

9

?

Page 10: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

10

Page 11: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

11

Page 12: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

12

Page 13: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

13

?

Page 14: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

14

Page 15: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

15

Page 17: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

1

2

3

4

5

617

U d/2 W d/2 V

Page 18: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

18Complexity

©D.Moshkovits

(a,b,c)=Is there a path from a to b, that takes no morethan c steps.

3Log2(d)

1

4

32

boolean PATH(a,b,d) {

if there is an edge from a to b then

return TRUE

else {

if (d=1) return FALSE

for every vertex v (not a,b) {

if PATH(a,v, d/2) and

PATH(v,b, d/2) then

return TRUE

}

return FALSE

}

}

(1,4,3)(1,4,3)(1,2,2)(1,4,3)(1,2,2)TRUE(1,4,3)(2,4,1)(1,4,3)(2,4,1)FALSE(1,4,3)(1,3,2)(1,4,3)(1,3,2)(1,2,1)(1,4,3)(1,3,2)(1,2,1)TRUE(1,4,3)(1,3,2)(2,3,1)(1,4,3)(1,3,2)(2,3,1)TRUE(1,4,3)(1,3,2)TRUE(1,4,3)(3,4,1)(1,4,3)(3,4,1)TRUE(1,4,3) TRUE

boolean PATH(a,b,d) {

if there is an edge from a to b then

return TRUE

else {

if (d=1) return FALSE

for every vertex v (not a,b) {

if PATH(a,v, d/2) and

PATH(v,b, d/2) then

return TRUE

}

return FALSE

}

}

boolean PATH(a,b,d) {

if there is an edge from a to b then

return TRUE

else {

if (d=1) return FALSE

for every vertex v (not a,b) {

if PATH(a,v, d/2) and

PATH(v,b, d/2) then

return TRUE

}

return FALSE

}

}

boolean PATH(a,b,d) {

if there is an edge from a to b then

return TRUE

else {

if (d=1) return FALSE

for every vertex v (not a,b) {

if PATH(a,v, d/2) and

PATH(v,b, d/2) then

return TRUE

}

return FALSE

}

}

boolean PATH(a,b,d) {

if there is an edge from a to b then

return TRUE

else {

if (d=1) return FALSE

for every vertex v (not a,b) {

if PATH(a,v, d/2) and

PATH(v,b, d/2) then

return TRUE

}

return FALSE

}

}

boolean PATH(a,b,d) {

if there is an edge from a to b then

return TRUE

else {

if (d=1) return FALSE

for every vertex v (not a,b) {

if PATH(a,v, d/2) and

PATH(v,b, d/2) then

return TRUE

}

return FALSE

}

}

boolean PATH(a,b,d) {

if there is an edge from a to b then

return TRUE

else {

if (d=1) return FALSE

for every vertex v (not a,b) {

if PATH(a,v, d/2) and

PATH(v,b, d/2) then

return TRUE

}

return FALSE

}

}

boolean PATH(a,b,d) {

if there is an edge from a to b then

return TRUE

else {

if (d=1) return FALSE

for every vertex v (not a,b) {

if PATH(a,v, d/2) and

PATH(v,b, d/2) then

return TRUE

}

return FALSE

}

}

boolean PATH(a,b,d) {

if there is an edge from a to b then

return TRUE

else {

if (d=1) return FALSE

for every vertex v (not a,b) {

if PATH(a,v, d/2) and

PATH(v,b, d/2) then

return TRUE

}

return FALSE

}

}

boolean PATH(a,b,d) {

if there is an edge from a to b then

return TRUE

else {

if (d=1) return FALSE

for every vertex v (not a,b) {

if PATH(a,v, d/2) and

PATH(v,b, d/2) then

return TRUE

}

return FALSE

}

}

boolean PATH(a,b,d) {

if there is an edge from a to b then

return TRUE

else {

if (d=1) return FALSE

for every vertex v (not a,b) {

if PATH(a,v, d/2) and

PATH(v,b, d/2) then

return TRUE

}

return FALSE

}

}

boolean PATH(a,b,d) {

if there is an edge from a to b then

return TRUE

else {

if (d=1) return FALSE

for every vertex v (not a,b) {

if PATH(a,v, d/2) and

PATH(v,b, d/2) then

return TRUE

}

return FALSE

}

}

boolean PATH(a,b,d) {

if there is an edge from a to b then

return TRUE

else {

if (d=1) return FALSE

for every vertex v (not a,b) {

if PATH(a,v, d/2) and

PATH(v,b, d/2) then

return TRUE

}

return FALSE

}

}

boolean PATH(a,b,d) {

if there is an edge from a to b then

return TRUE

else {

if (d=1) return FALSE

for every vertex v (not a,b) {

if PATH(a,v, d/2) and

PATH(v,b, d/2) then

return TRUE

}

return FALSE

}

}

Page 19: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

19

Page 20: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

20

Page 21: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

Premise

21

Page 22: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

22

Yes

No

Page 23: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

23

Page 24: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

24

Page 25: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

25

Induction:

Page 26: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

26

Page 27: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

reachs(v, l)

1. length = l; u = s

2. while (length > 0) {3. if u = v return ‘YES’

4. else, for all (u’ V) {

5. if (u, u’) E nondeterministic switch:

5.1 u = u’; --length; break

5.2 continue}

}6. return ‘NO’

27Complexity

©D.Moshkovits

Takes up logarithmic space

This N.D. algorithm might never stop

Page 28: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

CRs ( d )

1. count = 0

2. for all uV {3. countd-1 = 0

4. for all vV {5. nondeterministic switch:

5.1 if reach(v, d - 1) then ++countd-1 else fail

if (v,u) E then ++count; break5.2 continue

}

6. if countd-1 < CRs (d-1) fail

}

7.return count28Complexity

©D.Moshkovits

Recursive call!

Assume (v,v) E

Page 29: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

CRs ( d

1. count = 0

2. for all uV {3. countd-1 = 0

4. for all vV {5. nondeterministic switch:

5.1 if reach(v, d - 1) then ++countd-1 else fail

if (v,u) E then ++count; break5.2 continue

}

6. if countd-1 < fail

}

7.return count29Complexity

©D.Moshkovits

Main Algorithm:

CRs

C = 1

for d = 1..|V|

C = CR(d, C)

return C

parameter

C

, C)

Page 30: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

30

Page 31: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

Variables` range is

31

Page 32: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

32Complexity

©D.Moshkovits

xy[(xy)(xy)]

y[(0y)(0y)] y[(1y)(1y)]

(00)(00) (01)(01) (11)(11)(10)(10)

1 0 1

1

0

1

1

Page 33: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

33

Page 34: Explore space complexity - TAUsafra/Complexity/Space.pdf · Complexity 18 ©D.Moshkovits (a,b,c)=Is there a path from a to b, that takes no more than c steps. 3Log 2 (d) 1 4 3 2 boolean

34