Minesweeper is NP-Complete

Similar documents
Pythagorean Triples and SAT Solving

2 n Minesweeper Consistency Problem is in P

Chapter 34: NP-Completeness

CSE 105 THEORY OF COMPUTATION

The complexity of Minesweeper and strategies for game playing. Kasper Pedersen

Ian Stewart's article "Million-Dollar Minesweeper"

How to (Almost) Square a Circle

About the impossibility to prove P NP or P = NP and the pseudo-randomness in NP

Theory of Computer Science. Theory of Computer Science. E5.1 Routing Problems. E5.2 Packing Problems. E5.3 Conclusion.

Harvard CS 121 and CSCI E-121 Lecture 22: The P vs. NP Question and NP-completeness

Introduction to Computational Complexity

arxiv: v1 [cs.cc] 1 Feb 2016

A Simple Proof of P versus NP

Lecture 17: Cook-Levin Theorem, NP-Complete Problems

The Game of Cubic is NP-complete Erich Friedman Stetson University

Computability Theory

CS21 Decidability and Tractability

Instructor N.Sadagopan Scribe: P.Renjith. Lecture- Complexity Class- P and NP

CS154, Lecture 15: Cook-Levin Theorem SAT, 3SAT

1.1 P, NP, and NP-complete

Announcements. Friday Four Square! Problem Set 8 due right now. Problem Set 9 out, due next Friday at 2:15PM. Did you lose a phone in my office?

Introduction to Complexity Theory. Bernhard Häupler. May 2, 2006

Classes of Problems. CS 461, Lecture 23. NP-Hard. Today s Outline. We can characterize many problems into three classes:

On the Computational Hardness of Graph Coloring

A Lower Bound of 2 n Conditional Jumps for Boolean Satisfiability on A Random Access Machine

10.3: Intractability. Overview. Exponential Growth. Properties of Algorithms. What is an algorithm? Turing machine.

NP-Complete Reductions 1

Correctness of Dijkstra s algorithm

NP and NP Completeness

NP-Completeness Part II

A Lower Bound for Boolean Satisfiability on Turing Machines

The P = NP Problem Bristol Teachers Circle, June P.D.Welch, University of Bristol

Algorithm Design and Analysis

NP-Complete problems

Computational Complexity IV: PSPACE

NP Completeness. CS 374: Algorithms & Models of Computation, Spring Lecture 23. November 19, 2015

Show that the following problems are NP-complete

NP and Computational Intractability

CMSC 858F: Algorithmic Lower Bounds Fall SAT and NP-Hardness

Algorithms and Complexity Theory. Chapter 8: Introduction to Complexity. Computer Science - Durban - September 2005

SAT, NP, NP-Completeness

Theory of Computer Science

Intro to Theory of Computation

Theory of Computer Science. Theory of Computer Science. E2.1 P and NP. E2.2 Polynomial Reductions. E2.3 NP-Hardness and NP-Completeness. E2.

Nondeterministic Turing Machines

Foundations of Artificial Intelligence

DESIGN AND ANALYSIS OF ALGORITHMS. Unit 6 Chapter 17 TRACTABLE AND NON-TRACTABLE PROBLEMS

Unit 6 Chapter 17 TRACTABLE AND NON-TRACTABLE PROBLEMS

11. Tractability and Decidability

EECS 144/244: Fundamental Algorithms for System Modeling, Analysis, and Optimization

Intro to Theory of Computation

CMSC 858F: Algorithmic Lower Bounds Fall SAT and NP-Hardness

Theory of Computer Science

Self-assessment due: Monday 3/18/2019 at 11:59pm (submit via Gradescope)

Instructor N.Sadagopan Scribe: P.Renjith

Theory of Computer Science. Theory of Computer Science. E2.1 P and NP. E2.2 Polynomial Reductions. E2.3 NP-Hardness and NP-Completeness. E2.

Chapter 2. Reductions and NP. 2.1 Reductions Continued The Satisfiability Problem (SAT) SAT 3SAT. CS 573: Algorithms, Fall 2013 August 29, 2013

6.080 / Great Ideas in Theoretical Computer Science Spring 2008

PAijpam.eu A SHORT PROOF THAT NP IS NOT P

NP and NP-Completeness

The Maze Generation Problem is NP-complete

7.8: Intractability. Overview. Exponential Growth. Properties of Algorithms. What is an algorithm? Turing machine.

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: NP-Completeness I Date: 11/13/18

Algorithm Design and Analysis

NP-complete problems. CSE 101: Design and Analysis of Algorithms Lecture 20

NP-Completeness. A language B is NP-complete iff B NP. This property means B is NP hard

COMP 382. Unit 10: NP-Completeness

Theory of Computer Science. Theory of Computer Science. E3.1 Overview. E3.2 Cook-Levin Theorem E3.3 3SAT. E3.4 Summary. Further Reading (German)

A Tutorial on Euler Angles and Quaternions

Lecture 20: PSPACE. November 15, 2016 CS 1010 Theory of Computation

Lecture 4 Scribe Notes

Theory of Computer Science. Theory of Computer Science. E4.1 Overview E4.2 3SAT. E4.3 Graph Problems. E4.4 Summary.

GST 102: Spatial Analysis Lab Series Lab 8: Raster Data Analysis Density Surfaces

Zero-Sum Games Public Strategies Minimax Theorem and Nash Equilibria Appendix. Zero-Sum Games. Algorithmic Game Theory.

CS154, Lecture 13: P vs NP

CSE 555 HW 5 SAMPLE SOLUTION. Question 1.

Satisfiability A Lecture in CE Freshman Seminar Series: Ten Puzzling Problems in Computer Engineering. Apr Satisfiability Slide 1

6.045: Automata, Computability, and Complexity (GITCS) Class 15 Nancy Lynch

7.8 Intractability. Overview. Properties of Algorithms. Exponential Growth. Q. What is an algorithm? A. Definition formalized using Turing machines.

Recap from Last Time

P vs NP. Andzu Schaefer. January 2017

CS 320, Fall Dr. Geri Georg, Instructor 320 NP 1

CS 561, Lecture 12. Jared Saia University of New Mexico

Nondeterministic Polynomial Time

NP-Completeness I. Lecture Overview Introduction: Reduction and Expressiveness

Simultaneous equations 8 Introduction to advanced methods

CS 350 Algorithms and Complexity

CSC 373: Algorithm Design and Analysis Lecture 15

Langford s Problem. Moti Ben-Ari. Department of Science Teaching. Weizmann Institute of Science.

CSE 20 DISCRETE MATH WINTER

CS 301: Complexity of Algorithms (Term I 2008) Alex Tiskin Harald Räcke. Hamiltonian Cycle. 8.5 Sequencing Problems. Directed Hamiltonian Cycle

Notes for Lecture 3... x 4

The Cook-Levin Theorem

CS21 Decidability and Tractability

NP-Completeness. Algorithmique Fall semester 2011/12

Quantum-Dot Cellular Automata (QCA)

NP-Completeness. Sections 28.5, 28.6

4/30/14. Chapter Sequencing Problems. NP and Computational Intractability. Hamiltonian Cycle

4/19/11. NP and NP completeness. Decision Problems. Definition of P. Certifiers and Certificates: COMPOSITES

Transcription:

Minesweeper is NP-Complete Moti Ben-Ari Department of Science Teaching Weizmann Institute of Science http://www.weizmann.ac.il/sci-tea/benari/ c by Moti Ben-Ari. This work is licensed under the Creative Commons Attribution-ShareAlike. Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/ by-sa/./ or send a letter to Creative Commons, Castro Street, Suite, Mountain View, California,, USA.

This document assumes a basic knowledge NP-completeness. An overview of this topic is given in the Appendix. Richard Kaye showed that a puzzle based on the minesweeper game is NP-complete. This document presents Kaye s result with detailed explanations. Kaye, R. () Minesweeper is NP-complete. Mathematical Intelligencer (),. http://web.mat.bham.ac.uk/r.w.kaye/minesw/. The Minesweeper puzzle I will assume that you are familiar with if not addicted to the minesweeper game. There is a rectangular array of hidden cells partially filled with mines, and you have to uncover all non-mined cells without stepping on a mine. Cells adjacent to mines contain a number between and indicating the number of adjacent mines. The minesweeper puzzle is the opposite of the game: given an array in which some cells contain mines and some adjacency numbers, is there an an arrangement of mines that is consistent with the numbers? NP-completeness Kaye showed that the minesweeper puzzle is NP-complete by reducing instances of SAT (satisfiability of formulas of propositional logic) to instances of the puzzle. The SAT instances are given as circuits constructed of Boolean logic gates. Configurations of mines and adjacency numbers are constructed such that they are consistent iff they represent the logic gates not, and and or. In addition, configurations are needed to represent the wires in the circuit: straight wires, turns, crossovers, joiners and splitters. Minesweeper puzzles In this document, the cells are numbered from the lower left-hand corner right and up. An assignment of mines is consistent if it assigns mines to some of the open cells such that number of mines adjacent to each cell equals the number in the cell. A cell is fulfilled if the number in the cell is the same as the number of adjacent mines. If the number of mines is less than the number in the cell, the cell is not fulfilled. If the number of mines is greater than the number in the cell, or if there are not sufficient open cells in order to place mines so that the cell is fulfilled, the cell is said to be inconsistent. The following notation is used:

mine no mine? possible mine inconsistent cell fulfilled cell unfulfilled cell A simple puzzle a square of twos We first show that a mine cannot be placed in a corner cell. By symmetry, it is sufficient to show that a mine cannot be placed in cell (, ), the upper right-hand corner. If a mine is placed in (, ), the second mine needed to fulfill (, ) cannot be placed in (, ), because cells (, ), (, ), (, ) must be open, and there is no way to fulfill (, ). Suppose now that the second mine to fulfill (, ) is in cell (, ).

Two mines cannot be placed to fulfill (, ), because (, ), (, ), (, ) must be open. This proves that a mine cannot be placed in a corner cell. Next we show that there cannot be a mine in a cell adjacent to a corner cell. By symmetry, we show this for cell (, ). We can fulfill cell (, ) by placing a mine in cell (, ), but this forces (, ), (, ), (, ) to be open and (, ) cannot be fulfilled. Instead, let us try to fulfill cell (, ) by placing the second mine in cell (, ) and leaving (, ) open. To fulfill cell (, ) a mine must be placed in (, ) and to fulfill cell (, ) a mine must be placed in (, ), which also fulfills (, ). This forces cells in (, ), (, ), (, ) to be open, making (, ) inconsistent.

Since mines cannot be placed in a corner cell or in a cell adjacent to a corner cell, the only possible configuration is: A quick check shows that this configuration is consistent. A simple puzzle a square of threes In order to fulfull a cell containing that is not at a corner, mines must be placed in all of its adjacent open neighbors. For example, to fulfill (, ) there must be mines in (, ), (, ) and (, ).

When mines are placed to fulfill all non-corner cells, the four corner cells (, ), (, ), (, ) and (, ) will be inconsistent. Therefore, this puzzle has no solution. Digital Logic Circuits Kaye showed that CNF formulas in propositional logic, expressed as digital logic circuits, can be reduced to minesweeper puzzles. The formulas are reduced to circuits using not and or gates. (and gates can be constructed from or and not gates.) The connecting wires also have to be represented. We show the representation for straight wires; see Kaye s paper for the reduction for other forms of wires. P Q R And Or And Not Or Notation: an open cell followed by a cell with a mine (open/mine) represents, while a cell with a mine followed by an open cell (mine/open) represents.

Representation of a straight wire An input of mine/open () at (, ) (, ), results in an output of mine/open () at (, ) (, ): An input of open/mine () at (, ) (, ), results in an output of open/mine () at (, ) (, ):

Representation of a not gate An input of open/mine () at (, ) (, ) results in an output of mine/open () at (, ) (, ): There are mines at cells (, ) and (, ). Therefore, if there is an mine at (, ), the at (, ) forces (, ) to be open. It follows that there must be a mine at (, ) to fulfill (, ). It is now easy to see that (, ) is open, a mine is placed in (, ) and (, ) is open. Similarly, an input of mine/open () at (, ) (, ) results in an output of open/mine () at (, ) (, ):

Representation of an or gate The inputs are placed at (, ) (, ) and (, ) (, ). The result appears at (, ) (, ). We will show that if the input is open/mine () at the left and mine/open () at the top, then the result at the right is open/mine (). The reader is invited to check the solutions to the puzzle for ( or ), ( or ) and ( or ). The initial configuration is:

The at (, ) forces (, ) to be open, while the at (, ) forces a mine at (, ): Next, we need to place mines so that the at (, ) is adjacent to six mines. There are two possibilities: (), an open cell at (, ) and a mine at (, ), and (), an open cell at (, ) and a mine at (, ). Case There is an open cell at (, ) and a mine at (, ).

The at (, ) forces a mine (, ) and the at (, ) forces an open cell at (, ). The at (, ) forces an open cell at (, ) and the at (, ) forces mines at (, ), (, ).

The at (, ) forces an open cell at (, ). The at (, ) forces a mine at (, ) and the at (, ) forces an open cell at (, ), but now the at (, ) is inconsistent, because it is adjacent to only two mines.

Case An open cell at (, ) and a mine at (, ). The at (, ) forces an open cell at (, ) and the at (, ) forces a mine at (, ). In addition, the at (, ) forces a mine at (, ).

We now have two cases for the at (, ). Case. There is an open cell at (, ) and a mine at (, ). The at (, ) forces a mine at (, ) and the at (, ) forces an open cell at (, ). This in turn causes the at (, ) to force a mine at (, ), but now the at (, ) is inconsistent because the cell has four adjacent cells with mines.

Case. There is a mine at (, ) and an open cell at (, ). The at (, ) forces mines at (, ) and (, ).

The at (, ) forces an open cell at (, ), which is consistent with the at (, ). In addition, the at (, ) forces an open cell at (, ): The puzzle is now quickly solved successfully. The at (, ) forces a mine at (, ), which forces an open cell at (, ), which in turn forces a mine at (, ): The open cell at (, ) and the mine at (, ) form the output open/mine (), which is the result of ( or ).

Appendix A NP-completeness A problem Q is NP-complete if: A proposed answer to Q can be checked in polynomial time. All other problems in the class can be reduced to Q, meaning that if Q has a polynomial-time algorithm, then so do all the other problems. Given an assignment for a formula A in CNF, it is easy to check if the truth value of A is T, so SAT fulfills the first condition. Stephen Cook () and Leonid Levin () showed that the second condition also holds, so SAT is an NP-complete problem. The first condition states that an NP-complete problem can be solved in polynomial time by a non-deterministic algorithm. The question of whether NP-complete problems can be solved in polynomial time by a deterministic algorithm is called the P = N P? problem. If there is an efficient (deterministic polynomial-time) algorithm for one NP-complete problem, then there are efficient algorithms for all the problems in the class. Currently, no efficient algorithm is known for any problem in the class. If there is no efficient algorithm for one NP-complete problem, then there are no efficient algorithms for all the problems in the class. Currently, there is no proof that any of the problem in the class cannot be solved in deterministic polynomial time. The Clay Mathematics Institute offers a $ million prize for a proof that answers P = N P?. http://claymath.org/millennium-problems/p-vs-np-problem. NP-completeness is presented in textbooks in theoretical computer science such as: Hopcroft, J.E, Motwani, R., Ullman, J.D. Introduction to Automata Theory, Languages, and Computation, Third edition, Addison-Wesley,. Cormen, T.H., Leiserson, C.E., Rivest, R.L., Stein, C. Introduction to Algorithms, Second edition, MIT Press,. Sipser, M. Introduction to the Theory of Computation. PWS Publishing,.