easy, hard, and impossible

77
Easy, Hard, and Impossible

Upload: nellie

Post on 24-Feb-2016

47 views

Category:

Documents


0 download

DESCRIPTION

Easy, Hard, and Impossible. Easy. Tic Tac Toe. Hard. Chess. Recall the Approach - Search. Searching for the Best Move. A B C D E F G H I J K L M - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Easy, Hard, and Impossible

Easy, Hard, and Impossible

Page 2: Easy, Hard, and Impossible

Easy

Page 3: Easy, Hard, and Impossible

Tic Tac Toe

Page 4: Easy, Hard, and Impossible

Hard

Page 5: Easy, Hard, and Impossible

Chess

Page 6: Easy, Hard, and Impossible

Recall the Approach - Search

Page 7: Easy, Hard, and Impossible

Searching for the Best Move

A

B C D

E F G H I J K L M (8) (-6) (0) (0) (2) (5) (-4) (10) (5)

Page 8: Easy, Hard, and Impossible

How Much Computation Does it Take?

• Middle game branching factor 35• Lookahead required to play master level chess 8• 358

Page 9: Easy, Hard, and Impossible

How Much Computation Does it Take?

• Middle game branching factor 35• Lookahead required to play master level chess 8• 358 2,000,000,000,000• Seconds in a year

Page 10: Easy, Hard, and Impossible

How Much Computation Does it Take?

• Middle game branching factor 35• Lookahead required to play master level chess 8• 358 2,000,000,000,000• Seconds in a year 31,536,000• Seconds since Big Bang 300,000,000,000,000,000

Page 11: Easy, Hard, and Impossible

Growth Rates of Functions

Page 12: Easy, Hard, and Impossible

Yet Machines Can Do It

In 1997, Deep Blue beat Garry Kasparov.

Page 13: Easy, Hard, and Impossible

Seems Hard But Really Easy

Page 14: Easy, Hard, and Impossible

Nim

The player who takes the last stick(s) wins.

At your turn, you must choose a pile, then remove as many sticks from the pile as you like.

Page 15: Easy, Hard, and Impossible

Nim

Now let’s try:

Page 16: Easy, Hard, and Impossible

Nim

Now let’s try:

Oops, now there are a lot of possibilities to try.

Page 17: Easy, Hard, and Impossible

Nim

10 (2) 10 (2) 11 (3) 11

For the current player:• Guaranteed loss if last row is all 0’s.• Guaranteed win otherwise.

My turn:

Page 18: Easy, Hard, and Impossible

Nim

100 (4)010 (2)101 (5)011

For the current player:• Guaranteed loss if last row is all 0’s.• Guaranteed win otherwise.

My turn:

Page 19: Easy, Hard, and Impossible

Nim

100 (4)001 (1)101 (5)000

For the current player:• Guaranteed loss if last row is all 0’s.• Guaranteed win otherwise.

Your turn:

Page 20: Easy, Hard, and Impossible

Following Paths

Page 21: Easy, Hard, and Impossible

Seven Bridges of Königsberg

Page 22: Easy, Hard, and Impossible

Seven Bridges of Königsberg:

Seven Bridges of Königsberg

1

34

2

Page 23: Easy, Hard, and Impossible

Seven Bridges of Königsberg:

Seven Bridges of Königsberg

As a graph:

1

34

2

Page 24: Easy, Hard, and Impossible

For Any Graph

An Eulerian path : Cross every edge exactly once.

All these people care:

Bridge inspectors Road cleaners Network analysts

Page 25: Easy, Hard, and Impossible

Another Example

Page 26: Easy, Hard, and Impossible

Define the degree of a vertex to be the number of edges with it as an endpoint.

Another Example

Page 27: Easy, Hard, and Impossible

Define the degree of a vertex to be the number of edges with it as an endpoint.

Euler observed that:

● Eulerian path if and only if exactly two vertices of odd degree.

● Eulerian circuit if and only if all vertices have even degree.

Euler’s Observation

Page 28: Easy, Hard, and Impossible

An Efficient Algorithm

def eulerian_circuit(vertices, edges): for v in vertices: count = 0 for e in edges: if e touches v: count += 1 if odd(count): return(False) return(True)

How many steps does it take?

Page 29: Easy, Hard, and Impossible

An Efficient Algorithm

def eulerian_circuit(vertices, edges): for v in vertices: count = 0 for e in edges: if e touches v: count += 1 if odd(count): return(False) return(True)

How many steps does it take?

O(|vertices| * |edges|)

Page 30: Easy, Hard, and Impossible

Back to the Bridges

As a graph:

1

34

2

Page 31: Easy, Hard, and Impossible

The Good King and the Evil King

The good king wants to build exactly one new bridge so that:

• There’s an Eulerian path from the pub to his castle.

• But there isn’t one from the pub to the castle of his evil brother on the other bank of the river.

Page 32: Easy, Hard, and Impossible

Here’s What He Starts With

As a graph:

1

34

2

Page 33: Easy, Hard, and Impossible

Unfortuntately, There Isn’t Always a Trick

Suppose we need to visit every vertex exactly once.

Page 34: Easy, Hard, and Impossible

The Traveling Salesman Problem

Find the shortest circuit that visits every city exactly once.

15

20

25

89

23

40

10

4

73

28

Page 35: Easy, Hard, and Impossible

Visting Vertices Rather Than Edges

● A Hamiltonian path: visit every vertex exactly once.

● A Hamiltonian circuit: visit every vertex exactly once and end up where you started.

All these people care:• Salesmen, • Farm inspectors, • Network analysts

Page 36: Easy, Hard, and Impossible

The Traveling Salesman Problem

15

20

25

89

23

40

10

4

73

28

Given n cities:

Choose a first city nChoose a second n-1Choose a third n-2

… n!

Page 37: Easy, Hard, and Impossible

The Traveling Salesman Problem

Can we do better than n!

● First city doesn’t matter. ● Order doesn’t matter.

So we get (n-1)!/2.

Page 38: Easy, Hard, and Impossible

The Growth Rate of n!

2 2 11 4790016003 6 12 62270208004 24 13 871782912005 120 14 13076743680006 720 15 209227898880007 5040 16 3556874280960008 40320 17 64023737057280009 362880 18 12164510040883200010 3628800 19 243290200817664000011 39916800 36 3.61041

Page 39: Easy, Hard, and Impossible

Putting it into Perspective

Speed of light 3108 m/secWidth of a proton 10-15 mAt one operation in the time it takes light to cross a proton

31023 ops/sec

Since Big Bang 31017 secOps since Big Bang 91040 ops 36! = 3.61041

Neurons in brain 1011

Parallel ops since Big Bang

91051 43! = 61052

Page 40: Easy, Hard, and Impossible

1. Use a technique that is guaranteed to find an optimal solution and likely to do so quickly.

2. Use a technique that is guaranteed to run quickly and find a “good” solution.

Getting Close Enough

The Concorde TSP Solver found an optimal route that visits 24,978 cities in Sweden.

The World Tour Problem

Page 41: Easy, Hard, and Impossible

Is This The Best We Can Do?

It is generally believed that there’s no efficient algorithm that finds an exact solution to:

• The Traveling Salesman problem

• The question of whether or not a Hamiltonian circuit exists.

Would you like to win $1M?

The Millenium Prize

Page 42: Easy, Hard, and Impossible

Impossible

Page 43: Easy, Hard, and Impossible

An Interesting Puzzle

List 1 List 21 b bbb2 babbb ba3 ba a4 bbbaa babbb

2

List 1 b a b b b

List 2 b a

Page 44: Easy, Hard, and Impossible

An Interesting Puzzle

List 1 List 21 b bbb2 babbb ba3 ba a4 bbbaa babbb

2 1

List 1 b a b b b b

List 2 b a b b b

Page 45: Easy, Hard, and Impossible

An Interesting Puzzle

List 1 List 21 b bbb2 babbb ba3 ba a4 bbbaa babbb

2 1 1

List 1 b a b b b b b

List 2 b a b b b b b b

Page 46: Easy, Hard, and Impossible

An Interesting Puzzle

List 1 List 21 b bbb2 babbb ba3 ba a4 bbbaa babbb

2 1 1 3

List 1 b a b b b b b b a

List 2 b a b b b b b b a

Page 47: Easy, Hard, and Impossible

The Post Correspondence Problem

List 1 List 21 11 0112 01 03 001 110

Page 48: Easy, Hard, and Impossible

The Post Correspondence Problem

List 1 List 21 ab a2 ab ba3 aa baa

Page 49: Easy, Hard, and Impossible

The Post Correspondence Problem

List 1 List 21 ba bab2 abb bb3 bab abb

Page 50: Easy, Hard, and Impossible

The Post Correspondence Problem

List 1 List 21 1101 12 0110 113 1 110

http://webdocs.cs.ualberta.ca/~games/PCP/

Shortest solution has length 252.

Page 51: Easy, Hard, and Impossible

Can A Program Do This?

Can we write a program to answer the following question:

Given a PCP instance P, decide whether or not P has a solution.

Return:

True if it does.

False if it does not.

Page 52: Easy, Hard, and Impossible

The Post Correspondence ProblemA program to solve this problem:

Until a solution or a dead end is found:If dead end, halt and report no. Generate the next candidate solution.Test it. If it is a solution, halt and report yes.

So, if there are say 4 rows in the table, we’ll try:

1 2 3 4 1,1 1,2 1,3 1,4 1,5 2,1 …… 1,1,1 ….

Page 53: Easy, Hard, and Impossible

Will This Work?

• If there is a solution:

• If there is no solution:

Page 54: Easy, Hard, and Impossible

A Tiling Problem

Page 55: Easy, Hard, and Impossible

A Tiling Problem

Page 56: Easy, Hard, and Impossible

A Tiling Problem

Page 57: Easy, Hard, and Impossible

A Tiling Problem

Page 58: Easy, Hard, and Impossible

A Tiling Problem

Page 59: Easy, Hard, and Impossible

A Tiling Problem

Page 60: Easy, Hard, and Impossible

A Tiling Problem

Page 61: Easy, Hard, and Impossible

A Tiling Problem

Page 62: Easy, Hard, and Impossible

A Tiling Problem

Page 63: Easy, Hard, and Impossible

A Tiling Problem

Page 64: Easy, Hard, and Impossible

Another Tiling Problem

1 2 3

Page 65: Easy, Hard, and Impossible

Can A Program Do This?

Can we write a program to answer the following question:

Given a tiling problem T, decide whether or not T can tile a plane.

Return:

True if it can.

False if it can not.

Page 66: Easy, Hard, and Impossible

Deciding a Tiling Problem

A program to solve this problem:

Until the answer is clearly yes or a dead end is found:If dead end, halt and report no. Generate the next candidate solution.Test it. If it is a solution, halt and report yes.

Page 67: Easy, Hard, and Impossible

Will This Work?

• If T can tile a plane:

• If T can not tile a plane:

Page 68: Easy, Hard, and Impossible

Programs Debug Programs

name = input(“Type your name: ”)if name == “Elaine”: print (“You win!!”)else:

print (“You lose ”)

Given an arbitrary program, can it be guaranteed to halt?

Page 69: Easy, Hard, and Impossible

Programs Debug Programs

number = input(“Enter number: ”)result = 1counter = 2while counter <= number:

result = result * countercounter +=1

print (result)

Given an arbitrary program, can it be guaranteed to halt?

Page 70: Easy, Hard, and Impossible

Programs Debug ProgramsGiven an arbitrary program, can it be guaranteed to halt?

Suppose number = 5:result number counter 1 5 2 2 5 3 6 5 4 24 5 5120 5 6

number = input(“Enter number: ”)result = 1counter = 2while counter <= number:

result = result * countercounter +=1

print (result)

Page 71: Easy, Hard, and Impossible

Programs Debug ProgramsGiven an arbitrary program, can it be guaranteed to halt?

Suppose number = 5:result number counter 1 5 2 1 10 3 1 30 4 1 120 5 1 600 6

number = input(“Enter number: ”)result = 1counter = 2while counter <= number:

number = number * countercounter +=1

print (result)

Page 72: Easy, Hard, and Impossible

Programs Debug ProgramsGiven an arbitrary program, can it be guaranteed to halt?

Collatz Conjecture: This program always halts.

def threen(value): while value != 1:

if value % 2 == 0: value = value//2 else: value = 3 * value + 1 print(value)

Recall the 3n+1 problem:

Page 73: Easy, Hard, and Impossible

The Impossible

The halting problem cannot be solved.

We can prove that no program can ever be written that can:

• Look at an arbitrary program and decide whether or not it always halts.

• Look at an arbitrary program and a specific input and decide whether or not the program will halt on that input.

Page 74: Easy, Hard, and Impossible

Recall the Tiling Problem

Page 75: Easy, Hard, and Impossible

Recall the Post Correspondence Problem

List 1 List 21 ab a2 ab ba3 aa baa

Page 76: Easy, Hard, and Impossible

Which is Amazing

Given the things programs can do.

http://www.youtube.com/watch?v=Atmk07Otu9U

http://www.youtube.com/watch?v=cdgQpa1pUUE

Page 77: Easy, Hard, and Impossible

Which is Amazing

How does Watson win? http://www.youtube.com/watch?v=d_yXV22O6n4

Watch a sample round: http://www.youtube.com/watch?v=WFR3lOm_xhE

From Day 1 of the real match: http://www.youtube.com/watch?v=seNkjYyG3gI

Introduction: http://www.youtube.com/watch?v=FC3IryWr4c8

IBM’s site: http://www-03.ibm.com/innovation/us/watson/what-is-watson/index.html

Bad Final Jeopardy: http://www.youtube.com/watch?v=mwkoabTl3vM&feature=relmfu

Given the things programs can do.