VISUALIZATION-1

Concept Visualization for N-Queen Problem

Try to place “N” numbers of queens on an “N x N” chessboard so that none of the queens attacks each other.

Anisha Swain
Coffee with The UI Girl

--

Let’s play a simple puzzle game. Your task is to place two more Queens in of the given chessboard such that, there will no Queen attacking the others.

Solved it? Pretty simple, wasn’t it? The above problem already had 3 queens placed. Will you be able to place all the Queens from a start?

Try to place “N” numbers of queens on an “N x N” chessboard so that none of the queens attacks each other vertically, horizontally or diagonally. With every solution, you will be allowed to play the next level with the incremented number of “N”. Let’s start with a 4x4 board. Give it a try.

Are you stuck at a point and it is killing your time? But a computer can solve such puzzles faster. So how does it do that? Let’s try to figure it out.

Let’s dive deep into it…

The problem stated above is otherwise known as the N Queen Problem, which is a useful test problem for search algorithms. That is why, we might consider trying different search algorithms like BFS, DFS, GA(Genetic Algorithms), Backtracking etc for searching its solution. So let’s dive deep into each of these to figure out the best problem-solving approach for this particular problem.

Talking about BFS first, in this approach queens will be placed in every position in each column to check whether it is a solution. Let’s see how it works in an intuitive manner.

As you can see most of the arrangements are not even be close to being valid. Don’t you think this will lead to unnecessary wastage of time and will increase the time complexity exponentially? Well, try solving it with another intuitive visualization.

So that’s it for this article. I hope you have checked out the visualization and if you liked it then do not forget to tell us your thoughts in the comment section below.

If you want to connect with me, here I am at Twitter or Instagram

Announcement: we will be ding d3.js tutorials soon so stay tuned.

Follow our community LinkedIn group, Facebook Page and Twitter for more such articles and posts and meet like-minded people to collaborate.

--

--

Anisha Swain
Coffee with The UI Girl

MTS @Salesforce, Former SE@Red Hat,GHCI18 Scholar,Open Source Contributor, Computer Vision and Deep learning enthusiast. contact:https://twitter.com/anishaswain