Can visit all squares of a chessboard exactly once ?

Slides:



Advertisements
Similar presentations
Analysis of Algorithms
Advertisements

CSE 211 Discrete Mathematics
NP-Hard Nattee Niparnan.
Introduction to Graph Theory Instructor: Dr. Chaudhary Department of Computer Science Millersville University Reading Assignment Chapter 1.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.
Graph-02.
Chapter 8: Graph Algorithms July/23/2012 Name: Xuanyu Hu Professor: Elise de Doncker.
Reducibility Class of problems A can be reduced to the class of problems B Take any instance of problem A Show how you can construct an instance of problem.
Techniques for Dealing with Hard Problems Backtrack: –Systematically enumerates all potential solutions by continually trying to extend a partial solution.
1 Appendix B: Solving TSP by Dynamic Programming Course: Algorithm Design and Analysis.
The Mathematics of Chessboard Puzzles. The Closed Knight’s Tour.
NP-complete and NP-hard problems Transitivity of polynomial-time many-one reductions Concept of Completeness and hardness for a complexity class Definition.
CS 206 Introduction to Computer Science II 03 / 27 / 2009 Instructor: Michael Eckmann.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 27 Graphs and Applications.
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 27 Graph Applications.
Representing Relations Using Matrices
Hardness Results for Problems P: Class of “easy to solve” problems Absolute hardness results Relative hardness results –Reduction technique.
What is the first line of the proof? a). Assume G has an Eulerian circuit. b). Assume every vertex has even degree. c). Let v be any vertex in G. d). Let.
1 NP-Completeness Objectives: At the end of the lesson, students should be able to: 1. Differentiate between class P, NP, and NPC 2. Reduce a known NPC.
An Euler Circuit is a cycle of an undirected graph, that traverses every edge of the graph exactly once, and ends at the same node from which it began.
The Theory of NP-Completeness
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
CSE 326: Data Structures NP Completeness Ben Lerner Summer 2007.
Graphs and Trees This handout: Eulerian Cycles: Sufficiency of the condition Hamiltonian tour.
Analysis of Algorithms CS 477/677
CS 206 Introduction to Computer Science II 03 / 25 / 2009 Instructor: Michael Eckmann.
Example: HP ≤ p HC Hamiltonian Path –Input: Undirected Graph G = (V,E) –Y/N Question: Does G contain a Hamiltonian Path? Hamiltonian Cycle –Input: Undirected.
CSE 421 Algorithms Richard Anderson Lecture 27 NP Completeness.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
Complexity ©D.Moshkovitz 1 Paths On the Reasonability of Finding Paths in Graphs.
Backtracking.
Chapter 15 Graph Theory © 2008 Pearson Addison-Wesley.
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
NP-Complete Problems CSC 331: Algorithm Analysis NP-Complete Problems.
EECS 203: It’s the end of the class and I feel fine. Graphs.
Nattee Niparnan. Easy & Hard Problem What is “difficulty” of problem? Difficult for computer scientist to derive algorithm for the problem? Difficult.
Complexity Classes (Ch. 34) The class P: class of problems that can be solved in time that is polynomial in the size of the input, n. if input size is.
MCS 312: NP Completeness and Approximation algorithms Instructor Neelima Gupta
Lecture 5: Backtracking Depth-First Search N-Queens Problem Hamiltonian Circuits.
Euler and Hamilton Paths. Euler Paths and Circuits The Seven bridges of Königsberg a b c d A B C D.
Week 11 - Wednesday.  What did we talk about last time?  Graphs  Euler paths and tours.
HISTORY The problem was originally proposed in 1848 by the chess player Max Bezzel, and over the years, many mathematicians, including Gauss have worked.
CSE 326: Data Structures NP Completeness Ben Lerner Summer 2007.
DP TSP Have some numbering of the vertices We will think of all our tours as beginning and ending at 1 C(S, j) = length of shortest path visiting each.
Techniques for Proving NP-Completeness Show that a special case of the problem you are interested in is NP- complete. For example: The problem of finding.
Week 11 - Monday.  What did we talk about last time?  Binomial theorem and Pascal's triangle  Conditional probability  Bayes’ theorem.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 30 Graphs and Applications.
Explorers need maps: Abstraction, representations and graphs Paul Curzon Queen Mary University of London
CIRCUITS, PATHS, AND SCHEDULES Euler and Königsberg.
Graph theory and networks. Basic definitions  A graph consists of points called vertices (or nodes) and lines called edges (or arcs). Each edge joins.
Euler Paths and Circuits. The original problem A resident of Konigsberg wrote to Leonard Euler saying that a popular pastime for couples was to try.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Analysis & Design of Algorithms (CSCE 321)
Chapter 13 Backtracking Introduction The 3-coloring problem
The Theory of NP-Completeness 1. Nondeterministic algorithms A nondeterminstic algorithm consists of phase 1: guessing phase 2: checking If the checking.
CSC 252: Algorithms October 28, 2000 Homework #5: Graphs Victoria Manfredi (252a-ad) notes: -Definitions for each of the graph concepts are those presented.
Week 11 - Wednesday.  What did we talk about last time?  Graphs  Paths and circuits.
(CSC 102) Lecture 30 Discrete Structures. Graphs.
Hamiltonian Graphs Graphs Hubert Chan (Chapter 9.5)
Graphs: Definitions and Basic Properties
Richard Anderson Lecture 26 NP-Completeness
Richard Anderson Lecture 26 NP-Completeness
Eulerian tours Miles Jones MTThF 8:30-9:50am CSE 4140 August 15, 2016.
Hamiltonian Graphs Graphs Hubert Chan (Chapter 9.5)
BACKTRACKING- GENERAL METHOD
Introduction to Graph Theory Euler and Hamilton Paths and Circuits
Lecture 15: Graph Theory II
Presented By: David Miller
Euler and Hamilton Paths
Presentation transcript:

Can visit all squares of a chessboard exactly once ? by Krishna Mahesh Deevela Murali

Overview Problem Statement of Real World Problem Basic Concepts Formulating Graph Problem Solution to Graph Problem and Real world Problem Interesting Facts

Can visit all squares of a chessboard exactly once ? Our real world Problem is a very simple Question, it is to find if a Knight can legally visit every square on a Chessboard only once and Return to Starting position? If Knight’s tour Exist ?? If Yes!! when does it happen?? If Not!!! Why?? Topic sounds Interesting rite… so lets not waste time and jump into topic just like the Knight …

Basics: The Knight’s Legal Moves: Each move of a Knight comprises 2 directions as specified below. Explain how the knight moves just in case the audience can’t recall. 8 Possible Moves: 2UP, 1 left 2 UP, 1Right 1UP, 2Left 1UP, 2Right 2Down, 1 left 2 Down, 1Right 1Down, 2Left 1Down, 2Right

Solution to Graph Problem Hamilton Circuit A Hamiltonian cycle (or Hamiltonian circuit) is a cycle in an undirected graph which visits each vertex exactly once and also returns to the starting vertex. E.g 0,1,2,3,0 Hamilton Path A path visits each vertex of a graph once and only once. E.g 0,1,2,3

Formulating Graph Problem In a chessboard the vertices would represent the squares of the board and the edges would represent a knight’s legal moves between squares results in a graph as shown below, Known as Knight’s graph. Highlights : Every Vertex represents square on chessboard. Every edge is one legal move of a Knight.

Special Properties of Knight’s Graph MxN chessboard has MN vertices. i.e Number of Squares equal to Vertices. Graph is Undirected. Edges of equal length, i.e one legal Knight Move. Knight’s Move is Symmetric. A to B is equal to B to A. Every move of knight Alternates between black and white. i.e move from white square will always result in an ending position on a black square and vice-versa

Solution to Graph Problem The Knight’s Tour is a well-known classic problem. The objective is to move a knight, starting from any square on a chessboard, to every other square once. Note that the knight makes only L-shaped moves (two spaces in one direction and one space in a perpendicular direction). If we observe the Knight's Tour problem turns out to be an instance of the more general Hamiltonian path problem in graph theory. The problem of getting a closed Knight's Tour is similarly an instance of the Hamiltonian cycle problem.

Solution to Graph Problem We have 2 types of solutions, Hamiltonian Path when Knight starts at a vertex and doesn't end at the same vertex, Open Knight tour. Hamiltonian Cycle where starting vertex and final vertex is the same, thus resulting a Cycle, Closed tour. The Solution to both Closed and Open tour are same just that start and final vertices are going to same and different correspondingly.

Algorithm: We can use simple algorithm to find if Knights tour Exists on the given board or not. M x N be size of board i.e mn number of squares. Total number of moves would be A=m*n-1. Visited be a two dimentional array [M][N] initialized to false, when Knight visits this square it is set to true. I be integer between 0 & A representing the number of moves, intialially it is 0, and if knight completes the Path it is A. After Completeting the path if the one of next possible move results to initial position, it is a Closed tour, else it is Open Tour.

Algorithm move(x,y,i) if( (x < 0) OR (x ≥ M) OR (y < 0) OR (y ≥ N) )return false if( visited[x, y] = true ) return false if( m = M ) print “A solution has been found” print “ x, y ” //This starts printing the solution set visited[x, y] = true return true else //This is a valid move, but a tour has not been completed. set result = false OR Move( x+2, y+1, m+1) set result = false OR Move( x+2, y-1, m+1) set result = false OR Move( x-2, y+1, m+1) set result = false OR Move( x-2, y-1, m+1) set result = false OR Move( x+1, y+2, m+1) set result = false OR Move( x+1, y-2, m+1) set result = false OR Move( x-1, y+2, m+1) set result = false OR Move( x-1, y-2, m+1)

Algorithm move(x,y,i) contd.. 4. if( result = true ) //One of the 8 moves above led to a completed tour. print “ x, y ” return true Else //None of the moves from this position led to a successful tour. //Now we must backtrack and try a different path set visited[x, y] = false //Unvisit this location return false Hence our Real World Problem is Solved.. Using Knights Graph and Basic Graph Theory.

The Closed Knight’s Tour The Open Knight’s Tour where start and final vertex are different Are you finding it hard to believe this would even work... Then take a live look. http://commons.wikimedia.org/wiki/File:Knight%27s_tour_anim_2.gif#mediaviewer/File:Knight%27s_tour_anim_2.gif http://upload.wikimedia.org/wikipedia/commons/1/1e/Turk-knights-tour_anim.svg

100 ?? 10000?? 1 ?? No No No… it is biggerrrrrr 26,534,728,821,064 How many closed knight’s tours are there on an 8 × 8 board? How many open knight’s tours are there on an 8 × 8 board? 100 ?? 10000?? 1 ?? No No No… it is biggerrrrrr 26,534,728,821,064 If we have to find all the closed paths every human has to find 3500 diff paths Population of world 7 billion but no of paths are 26 trillion 19,591,828,170,979,904 19 Quadrillion

When does this Closed Knight’s Tour occur In 1991, Allen Schwenk completely determined which rectangular chessboards have a closed knight’s tour. An m × n chessboard with m <= n has a closed knight’s tour unless one or more of the following three conditions hold: (a) m and n are both odd; (b) m = 1, 2 or 4 ; (c) m = 3 and n = 4, 6 or 8. (explaination is not given due to complexity and time for condition c)

Condition (a): m and n are both odd. Recall that a legal move for a knight whose initial position is a white square will always result in an ending position on a black square and vice-versa. Hence, every tour representing the legal moves of a knight alternates between black and white squares.

Condition (a): m and n are both odd. Suppose m and n are both odd. There will exist an odd number of squares on the board. The number of black squares will not equal the number of white squares. No closed tour can exist.

Condition (b): m = 1, 2 or 4. Suppose m = 1 Suppose m = 2

Condition (b): m = 1, 2 or 4. For 4 × n boards we require a more complex coloring of the board than the traditional black and white coloring.

Condition (b): m = 1, 2 or 4. Note that a knight must move from a brown square to a black square. Likewise, a knight must move from a white square to a green square. Two closed cycles are now forced to exist and no closed tour exists for the 4×n board. Solomon Golomb Double and single loop in 4x5 board Double loop in 4x8 board

Closed tours of few Boards 18x18 board 5x6 8x3 10x3 6x6 30x30 7x6 7x8 5x8 8x6 12x3

60x60 board

Semi Magic Squares First semi-magic knight’s tour In each quadrant, the sum of the numbers equals 520 and each of the rows and columns adds to 130 The sum of the numbers in each 2x2 section is 130 Even after so many number patterns it is called semi magic because the diagonals did not also add to 260. Total of 140 semi magic knight’s tours are found. But not even a single fully magic knight’s tour in 8x8 is possible

Knight’s tours and cryptography A cryptotour is a puzzle in which the 64 words or syllables of a verse are printed on the squares of a chessboard and are to be read in the sequence of a knight’s tour.

Knight’s tours and 3-D patterns Four polygons formed by 16 knight moves and their tessellation of the plane Knight’s tour tessellations can even be used to create beautiful 3-D patterns such as astersphaira hexastersphaira

References.. Jelliss, George. ”Introducing Knight’s Tours.” http://homepages.stayfree.co.uk/gpj/ktn.htm “Knight’s Tours”- Ben Hill, Kevin Tostado “Closed Knight Tour on Rectangular Boards”- sciencedirect.com A. J. Schwenk, Which Rectangular Chessboards have a Knight.s Tour? Mathematics Magazine

Any Questions Thankyou..