Attribution Non-Commercial (BY-NC)

13 views

Attribution Non-Commercial (BY-NC)

- Cat Combination
- Mathematical Thinking - Problem-Solving and Proofs - Solution Manual II
- PC Matrices 2
- Foreign Donor Money in USA Elections
- School Project on java
- ASS4RD3901A32
- New Text Document (2)
- bcsopt
- Lecture 08
- Jee Countdown
- Word Search Paper
- puzzles on permutations
- Matrix and Determinant Calculation Process Using Scientific Calculator ghgh
- Permutation and Combination
- Iseet Maths
- Cyclesort - a curious little sorting algorithm
- Jee Advanced Mathematics Syllabus
- Tensors
- Malware Pattern Scanning Schemes Secure Against Black-box Analysis
- Probability Handouts

You are on page 1of 3

Abstract The n n puzzle game is played on a matrix of numbered tiles with 1 tile missing to allow tiles to shift. The goal is to order the tiles by a sequence of shifts. We provide a O(n2 )-time algorithm to decide when an initial conguration of the n n puzzle game is solvable. We also provide an algorithm solving the game in O(n3 ) moves and show that this is asymptotically optimal.

The game

We now dene the m n puzzle game. Let U = [m] [n]. We impose the taxi cab metric on U : for p = (i, j), q = (i , j ) U, d(p, q) = |i i | + |j j |. A special element B U , usually (m, n), will be designated as the blank. A game state is a bijection : U U . (p) = q means that in position p is the label q. A transposition permutation is a bijection : U U such that p, q U, p = q (p) = q, (q) = p, r U {p, q} (r) = r. represents interchanging the elements in positions p, q. A legal move from state is a transposition permutation interchanging p, q where (p) = B and d(p, q) = 1. The state of the game after application of is . A move interchanging p = (i, j), q = (i , j ) where the state just before the move is and (p) = B is a left move i i = i 1, a right move i i = i + 1, an up move i j = j 1, a down move i j = j + 1. The initial state of the game is some permutation : U U . The (one and only) player makes a sequence of legal moves and wins i the last state is the identity permutation. The 4 4 game with B = (4, 4) is most common and is often called the 15puzzle. It is not known when this game was rst sold but at least one version was sold by the Embossing Co. in 1865.

Notice that if the game is solvable and (B) = B, then in a winning sequence of moves, the number of left moves must equal the number of right moves and 1

the number of up moves must equal the number of down moves, simply because the blank ends up at the same position as where it started. So the number of transpositions must be even. So the initial permutation must be even. We generalize this idea below. Lemma 1. The m n puzzle game with initial state , where the blank starts in position p, is solvable only if the sign of is the same as that of d(p, B). I.e. only if ( is even i d(p, B) is even). The following algorithm computes the sign of a permutation a[1], . . . , a[n] of 1, . . . , n in time O(n), which is optimal. 1 sign(a[1, . . . , n]) 2 s0 3 i1 4 while i n 5 if i = a[i] 6 swap(a, i, a[i]) 7 s1s 8 else 9 i++ 10 return s To see the correctness of this, notice that after the kth iteration of the loop, s is the congruence class modulo 2 of the number of transpositions used so far to modify a and all elements before position i are in the correct position and at least k elements are in the correct position. So we can decide solvability of the m n game in time O(mn).

We claim that the condition in lemma 1 is sucient as well. (provided m, n 2) Lemma 2. Let 2 m n. The m n puzzle game with initial state , where the blank starts in position p, is solvable if the sign of is the same as that of d(p, B). Proof. We describe an algorithm solving it. We will suppose for now that B = (m, n) and generalize later. Suppose (m, n) = (2, 2). Through a sequence of d(p, B) moves, we can move the blank to position B. Let be the state after this is done. Then is even. By applying the 4 moves right, down, left, up, we can cyclically rotate the 3 non-blank labels. So all 3 even permutations with the blank in position B are reachable, including the identity. Now suppose n 3. We order 1 row at a time, starting from the top and working left to right. Suppose that at some point we have ordered i 1 rows

and the rst j 1 elements of row i and now we want to put (i, j) into position (i, j) without disturbing the elements in earlier positions. Also suppose that i m 2, j n 1. If (i, j) is already in position, then we are done. But otherwise, choose an L shaped set of positions that is 2 positions thick and not containing any positions that should be left undisturbed. This can be done since m, n 2 and i m 2 and j n 1. Move the blank around the position labeled (i, j) in a spiral fashion inside this L to propagate it to the correct position. E.g. suppose the L is a 3 2 matrix, (i, j) = (1, 1) is currently at position (3, 1), the blank is at position (2, 1). Then use up, left, down, down, right, up. This takes O(m + n) moves. To get the last element of the row into position, move (i, j) into the position just below position (i, j) and move the blank into the position just below that. Then use down, down, right, up, left, up, right, down, down, left, up. Note that this temporarily disturbs position (i, j 1). It only moves the labels in a 3 2 submatrix. This strategy can be used to order the last 2 rows as well by rotating our perspective by 90 degrees. At the end we will have a 2 2 submatrix containing the blank and the remaining labels. Since we have preserved the invariant that the sign of the permutation matches that of the distance of the blank from position B, this 2 2 subproblem can be solved in place as well. Now suppose B = (m, n). We can use the same basic strategy as before but order the rows furthest from B rst and work inwards. At the end we will have a 2 2 subproblem just as before, but now it will be somewhere in the middle. Notice that the above algorithm uses O((m + n)mn) moves.

To get a non-blank label from position p to q takes d(p, q) moves and each such move moves only that non-blank label. So the number of moves required to solve the game is at least pU {B} d((p), p). If is chosen uniformly at random from all solvable permutations, then p U E(d((p), p)) (m + n). By linearity of expectation, the expected number of moves required is at least ((m + n)mn)). In particular, there is an initial conguration requiring at least ((m+n)mn) moves, but the average case statement is stronger. Since our algorithm achieves this bound, it is optimal, up to a constant factor.

References

[1] Jaap Scherphuis, Jaaps Puzzle http://www.geocities.com/jaapsch/puzzles/fteen.htm 3 Page,

- Cat CombinationUploaded bypreethish
- Mathematical Thinking - Problem-Solving and Proofs - Solution Manual IIUploaded byMalarkey Snollygoster
- PC Matrices 2Uploaded byHector R.
- Foreign Donor Money in USA ElectionsUploaded byJoshua J. Israel
- School Project on javaUploaded byProjjal Gop
- ASS4RD3901A32Uploaded byAparnesh Roy
- New Text Document (2)Uploaded byEsoteric Paradox
- bcsoptUploaded bygorot1
- Jee CountdownUploaded byabhijeet_sangwan
- Lecture 08Uploaded bySeverina Mallari
- Word Search PaperUploaded bySitiNorhanumMuhdJani
- puzzles on permutationsUploaded bynchandrasekhar418
- Matrix and Determinant Calculation Process Using Scientific Calculator ghghUploaded bySwagata Sahoo
- Permutation and CombinationUploaded byKundanPratap
- Iseet MathsUploaded byram0976928
- Cyclesort - a curious little sorting algorithmUploaded byrabbarrabbar
- Jee Advanced Mathematics SyllabusUploaded byexamfarra
- TensorsUploaded byrobotsheepboy
- Malware Pattern Scanning Schemes Secure Against Black-box AnalysisUploaded byMukan Kuzey
- Probability HandoutsUploaded byAngelo Luigi Yasay
- AH Ramdon IndexUploaded byandrerpsimoes
- x1psolfin.pdfUploaded byeng2011tech
- Trade HierarchyUploaded bygsosz
- CpE 514DS Syllabus v1_JCaneteUploaded byEugene Andrew Abuan
- Lecture_CompositesUploaded bycrazynup
- PCM Syllabus IIT AdvancedUploaded byravneet7
- Prospectus of MathematicsUploaded byAjay Kumar
- 1003 Handouts MathUploaded byAqua
- Basics - Rust Cheat SheetUploaded byfddf gfgfg
- lab1Uploaded byMuhammad Mohsin Muazzam

- Chess BooksUploaded byAshani Ray
- Poem3Uploaded byAshani Ray
- Poem2Uploaded byAshani Ray
- Lichess Pgn 2016.12.30 Anonymous vs Anonymous.3mIr2kLTUploaded byAshani Ray
- PoemUploaded byAshani Ray
- LunchboxUploaded byAshani Ray
- Lichess Pgn 2016.12.31 Anonymous vs Anonymous.nln8hngQUploaded byAshani Ray
- Scotch GameUploaded byAshani Ray
- WinningChessPlan.pdfUploaded byAshani Ray
- bhagmilkhabhagUploaded byAshani Ray
- Singh AmUploaded byAshani Ray
- PoemUploaded byAshani Ray
- DDay reviewUploaded byAshani Ray
- AronyerDinRatriUploaded byAshani Ray
- 2015_01_10_Sicilian-BlackWon.pgnUploaded byAshani Ray
- PoemUploaded byAshani Ray
- Hume Aur Jee NekiUploaded byAshani Ray
- Chander PaharUploaded byAshani Ray
- 2015_01_10_Sicilian-BlackWon.pgnUploaded byAshani Ray
- 2015 01 10 TwoKnights-WhiteWon.pgnUploaded byAshani Ray
- FrozenUploaded byAshani Ray
- Positional Play ReviewUploaded byAshani Ray
- Game on Scandanavia nUploaded byAshani Ray
- Review SuryaUploaded byAshani Ray
- Kole Yan ChalUploaded byAshani Ray
- anardri2Uploaded byAshani Ray
- Singh Am ReturnsUploaded byAshani Ray
- misor_rohosya_info.pdfUploaded byAshani Ray
- furkeyUploaded byAshani Ray
- Abbott 121 Chess ProblemsUploaded bylordhavok33

- Roots in RubyUploaded byJabari Zakiya
- ES12LE2 ReviewerUploaded byJam Ramos
- (1026)Dpp 6 Solutions of Triangle and Conic Section b.pdf.TmpUploaded byNikhil Mittal
- 340notes.pdfUploaded byAmit K Awasthi
- Transport PhenomenaUploaded bychidapa
- 26023207 Maths Project for Class 10Uploaded byJohn Nguyen
- Autopomorphic Forms and L Functions for the Group GL n R D. Goldfeld Cambridge 2006 WW CopyUploaded byMatthew Prussman
- 2012 HSC Examination MathematicsUploaded byMathKeys
- Numerical Modeling for Simulation Transient Flow in Distribution System with Crank-Nicolson MethodUploaded byInternational Journal of Structronics & Mechatronics
- 1d Condution(2013) Finite Volume MethodUploaded byHuyTq
- Mechanics With MatlabUploaded byAlban Leandri
- USER GuidelinesUploaded bydrfgdzfg
- NCT2Uploaded byOduola Musa Olanrewaju
- Exercise Z Matrix CH4Uploaded byManjeet Bhatia
- Term Paper MathsUploaded byNavneet Singh
- Orszag 1971.pdfUploaded bymrjanus
- All Asymptotes Lesson PowerpointUploaded bygregory_k_sherman
- STAT2011-2017-exam-formulae.pdfUploaded byeccentricftw4
- 9709_s14_qp_12Uploaded bySaqib359
- Diff Geom Notes.pdfUploaded byVishyata
- 1. Lecture 01-Weighted Residual MethodsUploaded byfefahim
- CBSE Class 10 Mathematics Sample Paper-09 (for 2013)Uploaded bycbsestudymaterials
- Solve Linear System CalculatorUploaded bySaher
- Analysis Calculus.370Uploaded byAnonymous AV90SAXa5V
- Unit III Magnetostatics.docUploaded byVenkatesan Satheeswaran
- Angular Momentum and Kinetic EnergyUploaded byimfendi
- ConvolutionUploaded byvivek
- MP2 paperUploaded byEarl Querijero
- mathsUploaded byKalikivayi Shiva
- Quadrantal Spherical Triangles.docxUploaded byFebelyn Tapic

## Much more than documents.

Discover everything Scribd has to offer, including books and audiobooks from major publishers.

Cancel anytime.