ECS 220: Theory of Computation Chapter 1

Chapter 1: Prologue
slides © 2017, David Doty
ECS 220: Theory of Computation
based on “The Nature of Computation” by Moore and Mertens
Euler vs. Hamilton
Eulerian cycle: visits each edge exactly once
a
b
b
c
G2
G1
d
e
c
a
d
e
1.1: Crossing Bridges
2
Euler vs. Hamilton
Eulerian cycle: visits each edge exactly once
a
b
b
c
G2
G1
d
e
c
a
d
e
1.1: Crossing Bridges
2
Euler vs. Hamilton
Eulerian cycle: visits each edge exactly once
exists if and only if every node has even degree
a
b
b
c
G2
G1
d
e
c
a
d
e
1.1: Crossing Bridges
2
Euler vs. Hamilton
Eulerian cycle: visits each edge exactly once
exists if and only if every node has even degree
a
b
b
c
G2
G1
d
e
c
a
d
e
Eulerian path: not required to end at start node
1.1: Crossing Bridges
2
Euler vs. Hamilton
Eulerian cycle: visits each edge exactly once
exists if and only if every node has even degree
a
b
b
c
G2
G1
d
e
c
a
d
e
Eulerian path: not required to end at start node
1.1: Crossing Bridges
2
Euler vs. Hamilton
Eulerian cycle: visits each edge exactly once
exists if and only if every node has even degree
a
b
b
c
G2
G1
d
e
c
a
d
e
Eulerian path: not required to end at start node
exists if and only if all but up to two nodes have even degree
1.1: Crossing Bridges
2
Euler vs. Hamilton
Eulerian cycle: visits each edge exactly once
exists if and only if every node has even degree
Hamiltonian cycle: visits each node exactly once
a
b
b
c
G2
G1
d
e
c
a
d
e
Eulerian path: not required to end at start node
exists if and only if all but up to two nodes have even degree
1.1: Crossing Bridges
2
Euler vs. Hamilton
Eulerian cycle: visits each edge exactly once
exists if and only if every node has even degree
Hamiltonian cycle: visits each node exactly once
a
b
b
c
G2
G1
d
e
c
a
d
e
Eulerian path: not required to end at start node
exists if and only if all but up to two nodes have even degree
1.1: Crossing Bridges
2
Euler vs. Hamilton
Eulerian cycle: visits each edge exactly once
exists if and only if every node has even degree
Hamiltonian cycle: visits each node exactly once
exists if and only if… ?
a
b
b
c
G2
G1
d
e
c
a
d
e
Eulerian path: not required to end at start node
exists if and only if all but up to two nodes have even degree
1.1: Crossing Bridges
2
Euler vs. Hamilton
Eulerian cycle: visits each edge exactly once
Hamiltonian cycle: visits each node exactly once
exists if and only if every node has even degree
exists if and only if… ?
Assuming graph has n nodes:
1.2: Intractable Itineraries
3
Euler vs. Hamilton
Eulerian cycle: visits each edge exactly once
Hamiltonian cycle: visits each node exactly once
exists if and only if every node has even degree
exists if and only if… ?
Assuming graph has n nodes:
Algorithm to test
degree of every
node takes time…
1.2: Intractable Itineraries
3
Euler vs. Hamilton
Eulerian cycle: visits each edge exactly once
Hamiltonian cycle: visits each node exactly once
exists if and only if every node has even degree
exists if and only if… ?
Assuming graph has n nodes:
Algorithm to test
degree of every
node takes time…
n2
1.2: Intractable Itineraries
3
Euler vs. Hamilton
Eulerian cycle: visits each edge exactly once
Hamiltonian cycle: visits each node exactly once
exists if and only if every node has even degree
exists if and only if… ?
Assuming graph has n nodes:
Algorithm to enumerate
every path with n nodes
takes time…
Algorithm to test
degree of every
node takes time…
n2
1.2: Intractable Itineraries
3
Euler vs. Hamilton
Eulerian cycle: visits each edge exactly once
Hamiltonian cycle: visits each node exactly once
exists if and only if every node has even degree
exists if and only if… ?
Assuming graph has n nodes:
Algorithm to test
degree of every
node takes time…
Algorithm to enumerate
every path with n nodes
takes time…
n2
n!
= n(n-1)(n-2)…(2)(1)
> (2)(2)(2)…(2)(2)
= 2n
1.2: Intractable Itineraries
3
Is there a fast way to decide if a graph has a Hamiltonian path?
1.2: Intractable Itineraries
4
Is there a fast way to decide if a graph has a Hamiltonian path?
If there is a polynomial-time algorithm for this problem, then there are also
polynomial-time algorithms for thousands of other natural, important
problems that we also don’t know how to solve in sub-exponential time.
(This is because the Hamiltonian path problem is NP-complete, and those
other problems are contained in NP.)
1.2: Intractable Itineraries
4
Is there a fast way to decide if a graph has a Hamiltonian path?
If there is a polynomial-time algorithm for this problem, then there are also
polynomial-time algorithms for thousands of other natural, important
problems that we also don’t know how to solve in sub-exponential time.
(This is because the Hamiltonian path problem is NP-complete, and those
other problems are contained in NP.)
If so, is there a fast way to find an actual Hamiltonian path in a
graph? (search versus decision)
1.2: Intractable Itineraries
4
Is there a fast way to decide if a graph has a Hamiltonian path?
If there is a polynomial-time algorithm for this problem, then there are also
polynomial-time algorithms for thousands of other natural, important
problems that we also don’t know how to solve in sub-exponential time.
(This is because the Hamiltonian path problem is NP-complete, and those
other problems are contained in NP.)
If so, is there a fast way to find an actual Hamiltonian path in a
graph? (search versus decision)
YES! (homework)
1.2: Intractable Itineraries
4
Is there a fast way to decide if a graph has a Hamiltonian path?
If there is a polynomial-time algorithm for this problem, then there are also
polynomial-time algorithms for thousands of other natural, important
problems that we also don’t know how to solve in sub-exponential time.
(This is because the Hamiltonian path problem is NP-complete, and those
other problems are contained in NP.)
If so, is there a fast way to find an actual Hamiltonian path in a
graph? (search versus decision)
YES! (homework)
Is there a fast way to check if a given path in a graph is
Hamiltonian? (search versus verify solution)
1.2: Intractable Itineraries
4
Is there a fast way to decide if a graph has a Hamiltonian path?
If there is a polynomial-time algorithm for this problem, then there are also
polynomial-time algorithms for thousands of other natural, important
problems that we also don’t know how to solve in sub-exponential time.
(This is because the Hamiltonian path problem is NP-complete, and those
other problems are contained in NP.)
If so, is there a fast way to find an actual Hamiltonian path in a
graph? (search versus decision)
YES! (homework)
Is there a fast way to check if a given path in a graph is
Hamiltonian? (search versus verify solution)
YES!
1.2: Intractable Itineraries
4
Finding solutions vs. verifying purported solutions
1.3: Playing Chess with God
5
Finding solutions vs. verifying purported solutions
Hamiltonian path
input: graph G=(V,E)
output: Hamiltonian path in G
1.3: Playing Chess with God
5
Finding solutions vs. verifying purported solutions
Hamiltonian path
input: graph G=(V,E)
output: Hamiltonian path in G
verification algorithm for path
p: check that p has exactly
n=|V| unique nodes
1.3: Playing Chess with God
5
Finding solutions vs. verifying purported solutions
Hamiltonian path
Factoring
input: graph G=(V,E)
input: integer n > 1
output: Hamiltonian path in G
output: integers p,q > 1
such that pq = n
verification algorithm for path
p: check that p has exactly
n=|V| unique nodes
1.3: Playing Chess with God
5
Finding solutions vs. verifying purported solutions
Hamiltonian path
Factoring
input: graph G=(V,E)
input: integer n > 1
output: Hamiltonian path in G
output: integers p,q > 1
such that pq = n
verification algorithm for path
p: check that p has exactly
n=|V| unique nodes
verification algorithm for
integers p,q: check that pq=n
1.3: Playing Chess with God
5
Finding solutions vs. verifying purported solutions
Hamiltonian path
Factoring
input: graph G=(V,E)
input: integer n > 1
output: Hamiltonian path in G
output: integers p,q > 1
such that pq = n
verification algorithm for path
p: check that p has exactly
n=|V| unique nodes
verification algorithm for
integers p,q: check that pq=n
Multiplication
input: integers p,q
output: integer n where pq = n
1.3: Playing Chess with God
5
Finding solutions vs. verifying purported solutions
Hamiltonian path
Factoring
input: graph G=(V,E)
input: integer n > 1
output: Hamiltonian path in G
output: integers p,q > 1
such that pq = n
verification algorithm for path
p: check that p has exactly
n=|V| unique nodes
verification algorithm for
integers p,q: check that pq=n
Multiplication
input: integers p,q
output: integer n where pq = n
search algorithm for product
n: same as factoring!
(multiply pq to get n)
1.3: Playing Chess with God
5
Finding solutions vs. verifying purported solutions
Hamiltonian path
Factoring
Chess
input: graph G=(V,E)
input: integer n > 1
input: chess board positions
output: Hamiltonian path in G
output: integers p,q > 1
such that pq = n
output: checkmate strategy for white
verification algorithm for path
p: check that p has exactly
n=|V| unique nodes
verification algorithm for
integers p,q: check that pq=n
Multiplication
input: integers p,q
output: integer n where pq = n
search algorithm for product
n: same as factoring!
(multiply pq to get n)
1.3: Playing Chess with God
Checkmate in
262 moves
(Lewis Stiller,
1995)
5
Finding solutions vs. verifying purported solutions
Hamiltonian path
Factoring
Chess
input: graph G=(V,E)
input: integer n > 1
input: chess board positions
output: Hamiltonian path in G
output: integers p,q > 1
such that pq = n
output: checkmate strategy for white
verification algorithm for path
p: check that p has exactly
n=|V| unique nodes
verification algorithm for
integers p,q: check that pq=n
verification algorithm for sequence
of white-black chess moves: ???
(what if black moves differently?)
Multiplication
input: integers p,q
output: integer n where pq = n
search algorithm for product
n: same as factoring!
(multiply pq to get n)
1.3: Playing Chess with God
Checkmate in
262 moves
(Lewis Stiller,
1995)
5
Lofty ideas to cover in this course
1.4: What Lies Ahead
6
Lofty ideas to cover in this course
• Which problems have a “shortcut” leading to
a fast algorithm? Which require exhaustive
search?
1.4: What Lies Ahead
6
Lofty ideas to cover in this course
• Which problems have a “shortcut” leading to
a fast algorithm? Which require exhaustive
search?
• Many problems (Hamiltonian path, graph
coloring, Boolean satisfiability, balancing
integers, tiling, protein folding) are all equally
hard… why? What do they have in common?
How can we transform one into another?
1.4: What Lies Ahead
6
Lofty ideas to cover in this course
• Which problems have a “shortcut” leading to
a fast algorithm? Which require exhaustive
search?
• Many problems (Hamiltonian path, graph
coloring, Boolean satisfiability, balancing
integers, tiling, protein folding) are all equally
hard… why? What do they have in common?
How can we transform one into another?
• If there is an efficient algorithm to find
Hamiltonian paths, then there is an efficient
algorithm to find short proofs of the great
unsolved problems in mathematics (e.g.,
Riemann hypothesis). Is mathematics harder
than this, requiring intuition and creativity?
Can we prove that finding proofs is hard?
1.4: What Lies Ahead
6
Lofty ideas to cover in this course
• Which problems have a “shortcut” leading to
a fast algorithm? Which require exhaustive
search?
• Many problems (Hamiltonian path, graph
coloring, Boolean satisfiability, balancing
integers, tiling, protein folding) are all equally
hard… why? What do they have in common?
How can we transform one into another?
• Can one programming language solve
problems that another cannot? What is a
programming language exactly? We will see
examples of very simple systems of counters,
tiles, or billiard balls, that can do
computation.
• If there is an efficient algorithm to find
Hamiltonian paths, then there is an efficient
algorithm to find short proofs of the great
unsolved problems in mathematics (e.g.,
Riemann hypothesis). Is mathematics harder
than this, requiring intuition and creativity?
Can we prove that finding proofs is hard?
1.4: What Lies Ahead
6
Lofty ideas to cover in this course
• Which problems have a “shortcut” leading to
a fast algorithm? Which require exhaustive
search?
• Many problems (Hamiltonian path, graph
coloring, Boolean satisfiability, balancing
integers, tiling, protein folding) are all equally
hard… why? What do they have in common?
How can we transform one into another?
• Can one programming language solve
problems that another cannot? What is a
programming language exactly? We will see
examples of very simple systems of counters,
tiles, or billiard balls, that can do
computation.
• Can all problems be solved by an algorithm,
given unbounded time?
• If there is an efficient algorithm to find
Hamiltonian paths, then there is an efficient
algorithm to find short proofs of the great
unsolved problems in mathematics (e.g.,
Riemann hypothesis). Is mathematics harder
than this, requiring intuition and creativity?
Can we prove that finding proofs is hard?
1.4: What Lies Ahead
6
Lofty ideas to cover in this course
• Which problems have a “shortcut” leading to
a fast algorithm? Which require exhaustive
search?
• Many problems (Hamiltonian path, graph
coloring, Boolean satisfiability, balancing
integers, tiling, protein folding) are all equally
hard… why? What do they have in common?
How can we transform one into another?
• If there is an efficient algorithm to find
Hamiltonian paths, then there is an efficient
algorithm to find short proofs of the great
unsolved problems in mathematics (e.g.,
Riemann hypothesis). Is mathematics harder
than this, requiring intuition and creativity?
Can we prove that finding proofs is hard?
• Can one programming language solve
problems that another cannot? What is a
programming language exactly? We will see
examples of very simple systems of counters,
tiles, or billiard balls, that can do
computation.
• Can all problems be solved by an algorithm,
given unbounded time?
• How much memory is required for certain
problems? How does this related to the time
required for the problem?
1.4: What Lies Ahead
6
Lofty ideas to cover in this course
• Which problems have a “shortcut” leading to
a fast algorithm? Which require exhaustive
search?
• Many problems (Hamiltonian path, graph
coloring, Boolean satisfiability, balancing
integers, tiling, protein folding) are all equally
hard… why? What do they have in common?
How can we transform one into another?
• If there is an efficient algorithm to find
Hamiltonian paths, then there is an efficient
algorithm to find short proofs of the great
unsolved problems in mathematics (e.g.,
Riemann hypothesis). Is mathematics harder
than this, requiring intuition and creativity?
Can we prove that finding proofs is hard?
• Can one programming language solve
problems that another cannot? What is a
programming language exactly? We will see
examples of very simple systems of counters,
tiles, or billiard balls, that can do
computation.
• Can all problems be solved by an algorithm,
given unbounded time?
• How much memory is required for certain
problems? How does this related to the time
required for the problem?
• Algorithms are inherently deterministic. Can
flipping coins (randomness) help to solve
certain problems efficiently?
1.4: What Lies Ahead
6