0% found this document useful (0 votes)
9 views2 pages

Unit - 5

Uploaded by

Shiva Sanwale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Unit - 5

Uploaded by

Shiva Sanwale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Unit - 5

1
Q) 1.What is N Queen Problem?
In N-Queen problem, we are given an NxN chessboard and we have to place N number
of queens on the board in such a way that no two queens attack each other. A queen
will attack another queen if it is placed in horizontal, vertical or diagonal points in its
way. The most popular approach for solving the N Queen puzzle is Backtracking.
Input Output Scenario
Suppose the given chessboard is of size 4x4 and we have to arrange exactly 4 queens in
it. The solution arrangement is shown in the figure below −

The final solution matrix will be −


0010
1000
0001
0100
Backtracking Approach to solve N Queens Problem
In the naive method to solve n queen problem, the algorithm generates all possible
solutions. Then, it explores all of the solutions one by one. If a generated solution
satisfies the constraint of the problem, it prints that solution.
Follow the below steps to solve n queen problem using the backtracking approach −
 Place the first queen in the top-left cell of the chessboard.
 After placing a queen in the first cell, mark the position as a part of the solution
and then recursively check if this will lead to a solution.
Unit - 5
2
 Now, if placing the queen doesn’t lead to a solution. Then go to the first step and
place queens in other cells. Repeat until all cells are tried.
 If placing queen returns a lead to solution return TRUE.
 If all queens are placed return TRUE.
 If all rows are tried and no solution is found, return FALSE.

Q) 2.Branch and Bound Algorithm


The Branch and Bound Algorithm is a method used in combinatorial optimization
problems to systematically search for the best solution. It works by dividing the problem
into smaller subproblems, or branches, and then eliminating certain branches based on
bounds on the optimal solution. This process continues until the best solution is found
or all branches have been explored. Branch and Bound is commonly used in problems
like the traveling salesman and job scheduling.

You might also like