1 / 29

Self-Avoiding Walks of a Rook On an (M,N) Chessboard

Self-Avoiding Walks of a Rook On an (M,N) Chessboard. By: Jeffrey J. Denecke Robert S. Goldstein John L. Marcantonio Polytechnic University Department of Computer Science Farmingdale, NY 11735 as prepared for Professor Alan R. Davis Instructor of Advanced Algorithms.

magda
Download Presentation

Self-Avoiding Walks of a Rook On an (M,N) Chessboard

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Self-Avoiding Walks of a RookOn an (M,N) Chessboard By: Jeffrey J. Denecke Robert S. Goldstein John L. Marcantonio Polytechnic University Department of Computer Science Farmingdale, NY 11735 as prepared for Professor Alan R. Davis Instructor of Advanced Algorithms

  2. Some Preliminary Notes • GNU C/C++ Compiler • SMS JDK 1.1 Compiler • No code optimization based on hardware specific flags • No File Accesses • Minutes:Seconds.Fractions of a Second • ANSI C++, fork( ), pid_t

  3. Abstract • Methods to determine the number of self-avoiding walks a rook can make on an N X M chessboard. • Two Fundamental Components: • Algebraically Derived • Algorithmically Derived • Recursive Algorithm will produce reliable results

  4. What is a S.A.W. ? • NOT a Tool to Cut Wood! • A Walk which starts at a fixed origin • It passes through each vertex at most once

  5. What is a S.A.W on an NxM Chessboard? • NxM two dimensional square lattice • Move rook from lower left to upper right • NO duplication of visits to a vertex • Must follow movement of a rook • Horizontal or Vertical • No Distance limitations

  6. A Look at a Simple Solution • 3x3 Lattice => 12 Distinct Pathways • Simple Right?

  7. It is not as Simple as it seems ... • Image => graphical solution? • Very Time Consuming • Complexity Increases dramatically as the number of vertices increases

  8. Algebraic Solution for N=1 For N=1, (M,N)=1; For All M>0

  9. Algebraic Solution for N=2 • For N=2, (M,N)=2m-1; For All M>0

  10. Algebraic Solution at N=3 • Unlike its close relatives at N=1 and N=2 • No Clear Cut Answer • Function Type Formula Derived by H.L. Abbott and D. Hanson : • Exact Algebraic Formula by Abbot and Hanson :

  11. The Derivation of the Unknown • Purely algebraic solutions become too complex as N increases beyond 2 • We must use an algorithmic approach • We have base cases for when N=1 and N=2 • Where do we go from here?

  12. Recursion at N=3 • H.L. Abbot and D. Hanson show a recursive solution when N=3 which is: Why not apply recursion to the project as a whole?

  13. Recursion and the S.A.W. • What is the difficulty in finding a solution to this problem? • Every possible path must be examined • In light of this, recursion is an ideal choice • Recursion allows: • Traversal of a given path • Spawn off all instances at a choice juncture • Stop when destination is reached

  14. Performance Anticipated • Recursion algorithm appears simple, but is very costly in time and system resources • Algorithms of this kind are O(Nx) (np hard) • Where is the cost in our algorithm?

  15. Cost in the Main Program • Nested for loops • Pseudocode: for(I=0 and < # of Columns, increment I) for(J=0 and < # of Rows, increment J) if( J >=1) traverse()

  16. Cost Inside the Traversal Function • Multiple recursive function calls • Worst Case: 4 calls to itself • Best Case: 1 call to itself • Let’s See the pseudocode ….

  17. PseudoCode for Traversal If( Xpos !=0 AND VertexLeft !Touched) Touch Vertex AND Traverse from Left If( Xpos !=M AND VertexRight !Touched) Touch Vertex AND Traverse from Right If( Ypos !=0 AND VertexUp !Touched) Touch Vertex AND Traverse from Up If( Ypos !=N AND VertexDown !Touched) Touch Vertex AND Traverse from Down

  18. What does this all mean? • When N=1,2, or 3 => time is close to zero • If N=M: • Time in main consumed by nested for loops is about N2 • Time consumed by traversals is at worst a factor of 4 • Therefore we can hypothesize that for all NxM chessboards, time is O(N2)

  19. Time Results • Acquired using UNIX system call time :

  20. NxN Algorithm Performance

  21. Conclusions from First Algorithm • Time Complexity is heck of a lot more than O(N2) • Time is exponential => O(NM) • Due to this time complexity, answers can only be reached by limiting the domain • Limit the domain to 6x6 maximum

  22. Forking Processes • Call UNIX function fork() to spawn a new child process • Force the computer to compute problem in parallel rather than sequentially • Fork before traversal • forces new process for each fork to execute traversal and allow code to continue

  23. Forking PseudoCode For( I=0 AND < # of Columns, Increment I) For( J=0 AND < # of Rows, Increment J) if(J>=1) fork() AND then traverse()

  24. Sequential vs. Parallel Processing

  25. Problems With Forking • What problems can a fork cause? • Creates copy of memory • Creates copy of stack space • This eats up system resources • What about in our problem? • Computational intensive recursion creates a massive number of processes • This cripples the system

  26. Java Implementation Using Threads • Time improved (gathered using a timing class and synchronized functions): • Sacrifice centiseconds in smaller cases • Gains in seconds for larger cases

  27. NxN Performance We can see a distinct improvement !!!

  28. Conclusions • A S.A.W. of a chessboard with a rook is possible to determine for limited dimensions • For larger cases, better hardware support is needed • Fork() failed because it was done in Linux on a PC as opposed to a SunSparc

  29. Let’s Take a Look at the Java! Self-Avoiding Walks of a Rookon an (M,N) Chessboard in Java

More Related