Daa 250207 194917
Daa 250207 194917
Example:
Let’s place 4 queens on a 4×4 chessboard such that no two queens threaten each other.
o If it’s threatened, backtrack and try the next column in the current row.
4. Continue this process until all queens are placed or no solution exists.
hello dear 😎🫰
Ans to Ques No (2)
Algorithm:
• Try all rows in the current column. Do the following for every row.
o Then mark this [row, column] as part of the solution and recursively check if
placing queen here leads to a solution.
o If placing the queen in [row, column] leads to a solution then return true.
o If placing queen doesn’t lead to a solution then unmark this [row, column] then
backtrack and try other rows.
o If all rows have been tried and valid solution is not found return false to trigger
backtracking.
hello dear 😎🫰
Pseudo-Code
function solveNQueens(n):
board = initialize n x n board with 0
if placeQueens(board, 0, n) == true:
printSolution(board)
else:
print("No solution exists")
hello dear 😎🫰
Ans to Ques No (3)
Difference between NP-Hard and NP-Complete
NP-Hard NP-Complete
NP-Hard is the class of problems as hard as the
NP-complete is both NP and NP-hard.
hardest problems in NP.
Problems in NP-Hard do not need to be in the NP
Problems in NP-Complete are a subset of NP,
class.
Solutions may not be verifiable in polynomial time Solutions can be verified in polynomial time.
It focuses on the difficulty of solving the problem
It focuses on problems that are both difficult
but doesn’t always guarantee solution verification in
to solve and verifiable in polynomial time.
polynomial time.
Vertex a b c d e f
Color C1 C2 C1 C2 C1 C2
From here,
hello dear 😎🫰
Ans to Ques No (5)
(i) State Space Tree:
(ii) State Space Tree for If "girl must not sit in between 2 boys":
hello dear 😎🫰