Home » Machine Learning/Artificial Intelligence

# N-Queens Problem- A type of Constraint Satisfactory Problem in Artificial Intelligence

In this article, we are going to study a **famous Constraint Satisfactory Problem of Artificial Intelligence**. We will study what the **N-Queen problem** is, what set of constraints it has and how the agent works while keeping all these constraints satisfied, and how the goal state is reached by the agent?

Submitted by Monika Sharma, on May 30, 2019

**N-Queens problem** is a well-known Constraint Satisfactory Problem of Artificial Intelligence. In this problem, we have an **NxN** square grid board and we have **N queens** which need to be placed on them. The queens should be placed on the board in such a way so that it satisfies the below-mentioned constraints:

- No row should contain more than one queen placed in it
- No column should contain more than one queen placed in it.
- Not more than one queen should be placed in the single diagonal.
- No row or column should be left without any queen placed in it.

On summing up all the constraints, we can conclude that each row and each column should contain exactly one queen in them, neither more nor less than that.

In this series of problems, mostly there are grids whose size is even in number, like 4, 6, 8 and so on. It should be noted that the minimum number of the grid that we can have in this problem is 4, not less than that.

Here the **4-Queen** problem and the 8-Queen problem are the most popular in the N-Queen problem series. There can exist many solutions for solving this problem, which mean that the solution to these problems is not unique. Yet, one of those solutions to both these types are given below:

### 4-Queens problem

In the **4-Queens problem**, we have a **4x4 grid** and we have **4 queens** to place on it. The layout for the **4-Queens problem** while satisfying all the constraints is as follows:

### 8-Queens problem

In the **8-Queens problem**, we have an **8x8 grid** and we have **8-queens** to place on it. The layout for the **8-Queens problem** while satisfying all the constraints is as follows:

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions

**Ad:**
Are you a blogger? Join our Blogging forum.

Learn PCB Designing: PCB DESIGNING TUTORIAL