300 likes | 426 Views
CSci 4011. INHERENT LIMITATIONS OF COMPUTER PROGRAMS. TIME COMPLEXITY. Definition: Let M be a TM that halts on all inputs. The running time or time-complexity of M is the function f : N N, where f(n) is the maximum number of steps that M uses on any input of length n.
E N D
CSci 4011 INHERENT LIMITATIONS OF COMPUTER PROGRAMS
TIMECOMPLEXITY Definition: Let M be a TM that halts on all inputs. The running time or time-complexity of M is the function f : N N, where f(n) is the maximum number of steps that M uses on any input of length n. Definition: TIME(t(n)) = { L | L is a language decided by a O(t(n)) time Turing Machine }
P = TIME(nc) NP = NTIME(nc) c N c N IMPORTANTCOMPLEXITY CLASSES Problems where it is easy to find the answer. Problems where it’s easy to check the answer. If P = NP then generation is as easy as recognition.
HARDEST PROBLEMS IN NP Theorem: A language B is NP-complete if: Definition: A language B is NP-complete if: 1. B NP 2. Every A in NP is poly-time reducible to B (i.e. B is NP-hard) 2. A is NP-complete and A ·P B If B is NP-Complete and P NP, then There is no fast algorithm for B.
c e e b b b b a a a a d d d d c c 3-COLORING
3SAT P 3COLOR We transform a 3-cnf formula into a graph G so 3SAT G 3COLOR The transformation can be done in time polynomial in the length of
x1 x1 ? T F x2 x2 (x1⋁ x2⋁x2)
? T F (x1⋁ x2⋁x2) x1 x1 x2 x2 c13 c11 c12 c16 c14 c15
? T F (x1⋁x2⋁ x2) ∧(x2 ⋁ ¬x1 ⋁ ¬x1) x1 x1 x2 x2 c13 c13 c11 c12 c11 c12 c16 c14 c16 c15 c14 c15
? T F (x1⋁x2⋁ x2) ∧(x2 ⋁ ¬x1 ⋁ ¬x1) x1 x1 x2 x2 c13 c13 c11 c12 c11 c12 c16 c14 c16 c15 c14 c15
ENCODING CHESS A 8£8 chess board has 64 squares and 32 pieces: Each square can have one of 13 values: 4 bits +1 bit encodes turn information. CHESS = { 〈B〉 | B is a chess board and white canforce a win. }
HOW MUCH DISK DOES HARRY NEED? ≤376 How many moves at any level? W ≤9Q + 1K + 2B + 2R + 2N = 376 ≤1051 How many levels? D ≤(64)32⨉2 = 2193 ≈ 1051 1052 So, at most, WD≤ 10 positions By remembering whether each board B ∈CHESS, we can explore “only” D ≈1051 positions. HOW MUCH SPACE?
Definition: Let M be a deterministic TM that halts on all inputs. The space complexity of M is the function ƒ: N N, where ƒ(n) is the rightmost tape position that M reaches on any input of length n. Definition: Let M be a non-deterministic TM that halts on all inputs. The space complexity of M is the function ƒ: N N, where ƒ(n) is the rightmost tape position that M reaches on any branch of its computation on any input of length n.
{ L | L is a language decided by a O(t(n)) space deterministic Turing Machine } Definition: SPACE(t(n)) = { L | L is a language decided by a O(t(n)) space non-deterministic Turing Machine } Definition: NSPACE(t(n)) =
( x y x ) ( ( ( x x x y y y x x x ) ) ) x x y y # # 3SAT SPACE(n) x y # 0 0 0 1
¬ALLNFA∈NSPACE(n) ALLNFA = { 〈N〉 | N is an NFA and L(N) = Σ* } can_reject_a_string(N): (Q,Σ,δ,Q0,F) = remove_epsilons(N) S = Q0 for i∈{1, … , 2n}: if S⋂F = Ø: return True nextBit= guess() S = s∈Sδ(s,nextBit) if S⋂F = Ø: return True else: return False ¬ALLNFAis NP-Hard, but probably not in NP!
Assume a branch of a non-looping non-deterministic computation uses space k How many time steps can this branch have? k⨉|Q|⨉|Γ|k = 2O(k)
SAVITCH’S THEOREM Theorem: For any function f where f(n) n, NSPACE(f(n)) SPACE(f(n)2) Proof: Let N be a non-deterministic TM with space complexity f(n) Construct a deterministic machine M that simply tries each branch of N Since each branch of N uses space at most f(n), then M uses space at most f(n)
We need to simulate a non-deterministic computation while saving as much space as possible
Idea: Given two configurations c1 and c2 together with a number t, test whether N can get from c1 to c2 in t steps and space f(n) defcan_yield(N,c1, c2, t, f): if t = 1: if (c1 = c2) or (c2∈ next_conf(N,c1)): return True else: return False else: for cm∈ { f-cellconfigurations }: if can_yield(c1,cm,t/2,f) and can_yield(cm,c2,t/2,f): return True else: return False
SAVITCH’S THEOREM Theorem: For any function f where f(n) n NSPACE(f(n)) SPACE(f(n)2) Proof: Let N be a non-deterministic TM with space complexity f(n) We modify N so that when it accepts, it clears its tape and moves the head to the leftmost cell Construct a deterministic machine M that on input w, simply returns can_yield(N,q0w,caccept, 2df(n), f(n))
PSPACE = SPACE(nk) NPSPACE = NSPACE(nk) k N k N PSPACE = NPSPACE
EXAMPLE Let OTHELLO = { 〈B〉 | B is an othello position with a winning move for the current player. } Prove that OTHELLO∈ PSPACE.
P PSPACE? YES
NP PSPACE? YES
P NP PSPACE
nk EXPTIME = TIME(2 ) k ℕ Assume a deterministic Turing machine that halts on all inputs runs in space f(n) Question: At most how many time steps can this machine run for? f(n)⨉|Q|⨉|Γ|f(n) = 2O(f(n)) PSPACE EXPTIME
P NP PSPACE EXPTIME P ≠ EXPTIME