8^HN Queens Revisited

I once wrote a blog entry about 8 queens problem using backtrack. Backtrack is good for small n generating all solutions for n-queens problem. But what if the n is getting large? It performs very bad, since it runs exponentially (try n = 27 for this code).

Here is an interesting problem Who needs 8 Queens when you can have N. Note that we are to find one solution that satisfies the no-attacks requirements, not all the solutions as a backtrack does.

Dont panic. Read this paper: A Polynomial Time Algorithm for the N-Queens Problem. Oh dude, it is AMAZING (read: power of algorithms). In short, it utilizes a randomized approach with gradient-based heuristic local search. For a random permutation, swap where there is a reduction of attacking-conflicts. Besides, there are also other good (small) tips. It really broadened my algo knowledge base and it's not only for this particular n-queens problem but can be generalized for other searching problems. Kool.

Here is the final implementaion according to this paper. It runs very fast.


Leave a comment

Recent Entries

  • Running Spaz on WebOS Emulator

    > You got root, you got everything. Yeah, Palm Pre is hot these days. Now with the [webos emulator](http://www.geektang.com/2009/06/linuxwebos.html) and [ssh](http://www.geektang.com/2009/06/sshwebos.html) available, you can have...

  • Haskell Platform

    >The Haskell Platform is a blessed library and tool suite for Haskell distilled from Hackage, along with installers for a wide variety of systems. IOW,...

  • When MT Meets iPhone/iPod Touch

    Just found [iMT](http://plugins.movabletype.org/imt/). It's the iphone / ipod touch interface for mt4. So now you can add/edit blog entries / comments on your favorite device...

  • All Project Euler Problems Solved

    [Project Euler](http://projecteuler.net) continues to be fun. First reached 100% when there were 240 problems. And have successfully guarded that honor since =). (As of this...

  • Million Digits of E, Sqrt(2), Pi

    > More puzzles, more fun. Besides [acm oj](http://acm.tju.edu.cn/toj/ranklist.html) and [projecteuler](http://projecteuler.net), i also like to solve the puzzles on [spoj](http://spoj.pl). The ACM/ICPC rules are rather limited...

Close