Tetris NP

Download as pdf or txt
Download as pdf or txt
You are on page 1of 38

Tetris is Hard:

An Introduction to P vs NP

Based on Tetris is Hard, Even to


Approximate in COCOON 2003 by
Erik D. Demaine (MIT)
Susan Hohenberger (JHU)
David Liben-Nowell (Carleton)

Whats Your Problem?

A language is a set of strings:


PRIMES = {2, 3, 5, 7, 11, 13, 17, 19, 23, . . .}

We are interested in the following kind of decision problem:


Given x, is x PRIMES?
How much harder does this question get as x gets larger?

The Tetris Problem

So what do we mean by Tetris?


Offline Tetris: get to see entire piece sequence in advance.
Advanced level: the initial board is partially filled.
TETRIS = {"g, s# :
can play piece sequence s to clear entire gameboard g}

"g, s# TETRIS: given a gameboard and a piece sequence, can


we clear the entire board using the given sequence?
2

Instances of Decision Problems


Is 357667 PRIMES?

Is

"

TETRIS?

How much harder does this get as the gameboard gets bigger?
Find an algorithm A that decides if "g, s# TETRIS.
Measure resources consumed by A.

Measuring Resource Usage


How do we measure the resources consumed by A?
Be pessimistic.
Always consider the worst instance of a given size.
Resources: time, space.
Run A on all instances of size n on some computer.
Graph n versus the amount of each resource consumed
by A on the most consuming instance of size n.
5

12

200

x 10

180

10
160

140

120

100

80

4
60

40

2
20

Polynomial

10

10

12

14

16

18

Exponential

20

A Computer Theorists Worldview


Easy

Computable Uncomputable

Hard

Will 463 beat 363s median


on Quiz 3?
Will Windows crash when
I load this web page?
Can I color this map
with three colors?
Is this number prime?
Are all the numbers
in this list positive?
5

Complexity Classes
A complexity class is a set of languages.
A language L (PRIMES, TETRIS, ...) is a member of the
following complexity classes if there is an algorithm A ...
P

... deciding all questions x L in polynomial time.


e.g., for every x, time taken by A(x) is 10|x|3.
Games: JENGA

PSPACE ... deciding all questions x L in polynomial space.


Games: GO (in some countries), OTHELLO

EXPTIME

... deciding all questions x L in exponential time.


Games: CHESS, CHECKERS

Complexity Hierarchy
EXPTIME
PSPACE
!

Efficient Space

P
!

Efficient Time

P PSPACE EXPTIME
P &= EXPTIME

The Traveling Salesman Problem


Youre selling fair trade coffee beans.
Start at Deans Beans
World Headquarters in Dublin.
Visit (in any order):
Longs Bookstore, 1610 High St,
Cup of Joe, Easton Town Center,
446 Lane, Court House.
Drop off the leftovers in Dublin.
Can you do all deliveries in one hour?
What order should you use?
8

The Nave Solution to TSP


The nave method of solving TRAVELING-SALESMAN:
List all possible orderings of the cities.
Find the shortest ordering.
Check if it requires under one hour.
So TRAVELING-SALESMAN is in EXPTIME.
16 cities:
63 cities:

more orderings than the size of the US national debt.


more orderings than atoms in the known universe.
Can we do better?
9

Can we solve TSP efficiently??


Nobody has been able to:
give a faster solution to TRAVELING-SALESMAN.
prove that TRAVELING-SALESMAN needs exponential time.

So TRAVELING-SALESMAN might be in P!

But notice:
For a particular ordering of the coffeeshops, its easy to check
if the length of the trip is under one hour.
(Just add up the times.)
10

Guess and Check

Another way to measure the hardness of a language:


Suppose I claim that x L (and give you an argument to try to
convince you). How hard is it to check if my argument is right?

For example, for TETRIS: given "g, s#


I tell you all the moves m that Ill make in the game.
You check if moves m clear the gameboard g
using piece sequence s.
11

NP, continued
A language L is in NP if I can give you an argument A and
then you can check that A is right in polynomial time.
NP: Nondeterministic Polynomial Time
Nondeterminism: I give you an argument; you check it.
For some games, like CHESS, the move sequence might be
too long to check in polynomial time!

Summary: L P can be decided quickly.


L NP can be checked quickly.
12

Complexity Hierarchy
EXPTIME

PSPACE
!

NP
!

P
!

Chess, Checkers
Go, Othello, Sokoban,
Generalized Geography, Hex
Tetris, Mastermind,
Minesweeper, Sliding Blocks,
Traveling Salesman
Jenga, Im Thinking of a Number
P &= EXPTIME

P NP PSPACE EXPTIME

13

P vs. NP
NP&=P
We do not know which is true!

P=NP

One of the greatest unsolved problems in theoretical


computer science (and all of mathematics!).
Clay Mathematics Institute offers $1 million for solution.
Is it easier to verify a correct solution to a problem than it
is to solve the problem from scratch?
Huge impact on cryptography, airline scheduling, factory
layout, UPS truck packing, drug design, etc., etc., etc., etc.
14

NP-completeness
First major step on P vs. NP problem [Cook and Levin, 1970s]:
An NP-complete problem:
!

1. is in NP
2. is as hard as the hardest problem in NP.

NP

If we can quickly decide one


NP-complete problem, then we can
quickly decide them all. (P=NP)
If any problem is in NP and not P,
then every NP-complete problem
is in NP and not P. (P&=NP)
15

Technique #1: Divine Inspiration

Theorem [Cook/Levin]: SATISFIABILITY is NP-complete.

16

Technique #1: SAT is NP-complete

SATISFIABILITY = { formulas : there is a way of setting


the variables of so that is true }
e.g., x (x y) SATISFIABILITY.
(set x := true and y := false)

Theorem [Cook/Levin]: SATISFIABILITY is NP-complete.

16

Technique #2: Reduction


A reduction f is a mapping from one problem to another.
A

B
f
f

xA
if and only if
f (x) B.
Were interested
in efficient f .

If theres a quick algorithm for B, then theres one for A.


If theres no quick algorithm for A, then theres none for B.
B is as hard as A
17

NP-Completeness Summary

Theorem: SATISFIABILITY is NP-complete.


Cook/Levin.

Theorem: If: (1) A is NP-complete,


(2) B is in NP, and
(3) there is an efficient reduction from A to B
then B is NP-complete.

Karp.

18

Enough already! I came for the Tetris ...

To show that TETRIS is NP-complete:


Define efficient mapping m from instances of known
NP-Complete problem L to TETRIS.
Show that if x L, then m(x) TETRIS.
Show that if x
/ L, then m(x)
/ TETRIS.

19

From 3-PARTITION to TETRIS

3-PARTITION = {sets of integers that can be separated into


piles of three integers each, where each pile has the same sum}
Theorem [Garey and Johnson]: 3-PARTITION is NP-complete.

Our result:
There is an efficient reduction from 3-PARTITION to TETRIS.

20

Our Reduction ...


Given integers a1, . . . , a3s and the target sum T for each pile:
a1

initiator:
filler (a1 times):

6T + 22

terminator:

...

a2

initiator:
...

a3s

terminator:

Finally:
6s + 3

...

s,

, and

( 3T
2 + 5).
21

Reminder: NP-Completeness

To show that Tetris is NP-complete:

Define efficient mapping m from instances of


3-PARTITION to TETRIS.
Show that if x 3-PARTITION, then m(x) TETRIS.
Show that if x
/ 3-PARTITION, then m(x)
/ TETRIS.

22

For x L, we need m(x) TETRIS


Yes means yes.
If we have x 3-PARTITION, then need m(x) TETRIS.
Pile the integers according to their 3-PARTITION piles.

..

23

The yes case, continued


Piles each have the same sum, so they have the same height:
Each bucket is filled exactly to the top.

Remaining pieces will exactly clear entire gameboard.


24

Reminder: NP-Completeness

To show that TETRIS is NP-complete:

Define efficient mapping m from instances of


3-PARTITION to TETRIS.
Show that if x 3-PARTITION, then m(x) TETRIS.
Show that if x
/ 3-PARTITION, then m(x)
/ TETRIS.

25

Why this reduction?


We want to make sure that no means no.

cant clear any rows until the

...

have to completely fill each bucket


or its all over.
notches make it easy to get stuck.

26

For x
/ L, we need m(x)
/ TETRIS
No means no.
Step #1: if you dont (or cant) make the moves from two
slides ago, you get into one of the following configurations.
Step #2: if you get into one of these, youre hosed.

not div. by 4

27

Reminder: NP-Completeness

To show that Tetris is NP-complete:

Define efficient mapping m from instances


of 3-PARTITION to TETRIS.
Show that if x 3-PARTITION, then m(x) TETRIS.
Show that if x
/ 3-PARTITION, then m(x)
/ TETRIS.
Theorem: TETRIS is NP-complete.

28

Statement of Results

Our results actually apply for some other Tetris questions, too:
can we clear at least k rows?
can we place at least p pieces without losing?
can we place all pieces without filling a square at height h?
can we achieve at least t tetrises?
All of these are NP-complete.
29

Other Objectives and Inapproximability

Can strengthen our results further:


add a boatload of

pieces

to our sequence.
Can get into (and clear) lower
reservoir (using extra

pieces)

only if can clear the top using original.


Choosing a large reservoir yields
inapproximability results.

30

Other Work on Tetris

Theorem: A (sufficiently long) alternating


sequence of

s and

s will cause a loss.

[Brzustowski/Burgiel]
Implies that probability of a real Tetris game lasting infinitely
long is zero (regardless of players skill).
On the Tetris gameboard that you know and love.
(Our complexity results are as the gameboard grows.)
31

Conclusion and Open Questions


Many interesting problems are NP-complete.
(Traveling Salesman, Minesweeper, Tetris, Satisfiability, ...)
So what? Does P = NP?
Is it easier to verify that a solution is correct
than it is to come up with it from scratch?
Games are interesting because theyre hard (?)
Easy way to make a million bucks:
give an efficient algorithm for TETRIS!
32

Recap: Proving Membership in NP

SATISFIABILITY = { formula : there is a way of setting the


variables of so that is true }
Certificate: assignment to variables
Verifier: plugs in assignment and tests that is true

33

Recap: Proving Membership in NP


SATISFIABILITY = { formula : there is a way of setting the
variables of so that is true }
Certificate: assignment a to variables
Verifier: tests that is true with assignment a
CLIQUE = { graph G and integer k : there is a clique of size k
in G}
Certificate: nodes in the clique C
Verifier: tests that each node in C is connected to every other
node in C
34

Recap: Optimization vs Decision

SATISFIABILITY = { formula : there is a way of setting the


variables of so that is true }
Suppose P = NP.
How can you find a satisfying assignment in polynomial time?

35

Recap: Optimization vs Decision

CLIQUE = { graph G and integer k : there is a clique of size k


in G}
Suppose P = NP.
How can you find a k-clique in polynomial time?

36

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy