SlideShare a Scribd company logo
1
W E L C O M E !
Thank you for coming today!
2
MD. A.I.Tazib
ID: 153-15-6683
INTRODUCTION
5
N Q u e e n
P r o b l e m
The N Queen is the problem of placing N
chess queens on an N×N chessboard so that
no two queens attack each other.
For example, following is a solution for 4
Queen problem.
Solutions
V a r i o u s a p p r o a c h e s :
7
Brute force
Backtracking
Permutation
generation
Graph theory
concepts
Divide and conquer
approach
Mathematical
solutions
Backtracking Solution :
0
1
2
3
0 1 2 3
0
1
2
3
Positions:
9
F i n a l
S o l u t i o n
Q
Q
Q
Q
Bac k trac k ing
Algorithm
Backtracking Algorithm :
1) Start from the left most column.
2) If all Queens are placed
return true.
3) Try all rows in the current column. Do following for every tried row.
a) If the queen can be placed safely in this row then mark this [row,
column] as part of the solution and recursively check if placing
queen here leads to a solution.
b) If placing queen in [row, column] leads to a solution then return
true.
c) If placing queen doesn't lead to a solution then unmark this [row,
column] (Backtrack) and go to step (a) to try other rows.
4) If all rows have been tried and nothing worked, return false to trigger
backtracking.
T H A N K Y O U !
A N Y Q U E S T I O N S ?
Ad

Recommended

N queen problem
N queen problem
Ridhima Chowdhury
 
The n Queen Problem
The n Queen Problem
Sukrit Gupta
 
N queens using backtracking
N queens using backtracking
srilekhagourishetty
 
N queen puzzle
N queen puzzle
Akash Sethiya
 
Backtracking Algorithm.ppt
Backtracking Algorithm.ppt
SalmIbrahimIlyas
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
Madhu Bala
 
Graph coloring problem
Graph coloring problem
V.V.Vanniaperumal College for Women
 
Greedy method
Greedy method
Anusha sivakumar
 
Travelling salesman dynamic programming
Travelling salesman dynamic programming
maharajdey
 
Prim's algorithm
Prim's algorithm
Pankaj Thakur
 
8 queens problem using back tracking
8 queens problem using back tracking
Tech_MX
 
8 queen problem
8 queen problem
NagajothiN1
 
Branch & bound
Branch & bound
kannanchirayath
 
Tsp branch and-bound
Tsp branch and-bound
Saravanan Natarajan
 
Divide and conquer
Divide and conquer
Dr Shashikant Athawale
 
All pairs shortest path algorithm
All pairs shortest path algorithm
Srikrishnan Suresh
 
N Queens problem
N Queens problem
Arkadeep Dey
 
Backtracking
Backtracking
subhradeep mitra
 
sum of subset problem using Backtracking
sum of subset problem using Backtracking
Abhishek Singh
 
Greedy algorithms
Greedy algorithms
sandeep54552
 
01 knapsack using backtracking
01 knapsack using backtracking
mandlapure
 
Shortest path algorithm
Shortest path algorithm
sana younas
 
Knapsack Problem
Knapsack Problem
Jenny Galino
 
I. AO* SEARCH ALGORITHM
I. AO* SEARCH ALGORITHM
vikas dhakane
 
0/1 knapsack
0/1 knapsack
Amin Omi
 
Minimum spanning tree
Minimum spanning tree
Hinal Lunagariya
 
Backtracking
Backtracking
Vikas Sharma
 
Branch and bound
Branch and bound
Dr Shashikant Athawale
 
N Queen Problem
N Queen Problem
FoodieVlogger
 
Ai lecture 10(unit02)
Ai lecture 10(unit02)
vikas dhakane
 

More Related Content

What's hot (20)

Travelling salesman dynamic programming
Travelling salesman dynamic programming
maharajdey
 
Prim's algorithm
Prim's algorithm
Pankaj Thakur
 
8 queens problem using back tracking
8 queens problem using back tracking
Tech_MX
 
8 queen problem
8 queen problem
NagajothiN1
 
Branch & bound
Branch & bound
kannanchirayath
 
Tsp branch and-bound
Tsp branch and-bound
Saravanan Natarajan
 
Divide and conquer
Divide and conquer
Dr Shashikant Athawale
 
All pairs shortest path algorithm
All pairs shortest path algorithm
Srikrishnan Suresh
 
N Queens problem
N Queens problem
Arkadeep Dey
 
Backtracking
Backtracking
subhradeep mitra
 
sum of subset problem using Backtracking
sum of subset problem using Backtracking
Abhishek Singh
 
Greedy algorithms
Greedy algorithms
sandeep54552
 
01 knapsack using backtracking
01 knapsack using backtracking
mandlapure
 
Shortest path algorithm
Shortest path algorithm
sana younas
 
Knapsack Problem
Knapsack Problem
Jenny Galino
 
I. AO* SEARCH ALGORITHM
I. AO* SEARCH ALGORITHM
vikas dhakane
 
0/1 knapsack
0/1 knapsack
Amin Omi
 
Minimum spanning tree
Minimum spanning tree
Hinal Lunagariya
 
Backtracking
Backtracking
Vikas Sharma
 
Branch and bound
Branch and bound
Dr Shashikant Athawale
 
Travelling salesman dynamic programming
Travelling salesman dynamic programming
maharajdey
 
8 queens problem using back tracking
8 queens problem using back tracking
Tech_MX
 
All pairs shortest path algorithm
All pairs shortest path algorithm
Srikrishnan Suresh
 
sum of subset problem using Backtracking
sum of subset problem using Backtracking
Abhishek Singh
 
01 knapsack using backtracking
01 knapsack using backtracking
mandlapure
 
Shortest path algorithm
Shortest path algorithm
sana younas
 
I. AO* SEARCH ALGORITHM
I. AO* SEARCH ALGORITHM
vikas dhakane
 
0/1 knapsack
0/1 knapsack
Amin Omi
 

Similar to N Queen Algorithm (20)

N Queen Problem
N Queen Problem
FoodieVlogger
 
Ai lecture 10(unit02)
Ai lecture 10(unit02)
vikas dhakane
 
N-queens.pptx
N-queens.pptx
anoop2708
 
Backtracking Algorithm.pptx
Backtracking Algorithm.pptx
sangeeta194160
 
8 QUEENS PROBLEM.pptx
8 QUEENS PROBLEM.pptx
sunidhi740916
 
N queens problem
N queens problem
A. S. M. Shafi
 
PUZZLE IN C PROGRAMMING
PUZZLE IN C PROGRAMMING
AtchayaaM
 
Puzzle in c program
Puzzle in c program
NabishaAK
 
The N-Queens problemdskksnjfnskjdfnsjnddjsdnjs
The N-Queens problemdskksnjfnskjdfnsjnddjsdnjs
aadarsh4881
 
8 Queens Problemyjjffhhhgfghhhfhhggghjgg
8 Queens Problemyjjffhhhgfghhhfhhggghjgg
hariombhoria70
 
Backtracking Basics.pptx
Backtracking Basics.pptx
sunidhi740916
 
An approach to solve the N-Queens Problem using Artificial Intelligence algor...
An approach to solve the N-Queens Problem using Artificial Intelligence algor...
IRJET Journal
 
backtracking 8 Queen.pptx
backtracking 8 Queen.pptx
JoshipavanEdduluru1
 
module5_backtrackingnbranchnbound_2022.pdf
module5_backtrackingnbranchnbound_2022.pdf
Shiwani Gupta
 
proficiency presenattion on topic of backtracking algo
proficiency presenattion on topic of backtracking algo
sj9399037128
 
Constraint Satisfaction Problem (CSP) by A z m jalal uddin joy_v1.0.1
Constraint Satisfaction Problem (CSP) by A z m jalal uddin joy_v1.0.1
A. Z. M. JALAL UDDIN JOY
 
Genetic Algorithm Artificial Intelligence
Genetic Algorithm Artificial Intelligence
LamisaNoor
 
data structures- back tracking
data structures- back tracking
Abinaya B
 
Lecture2b algorithm
Lecture2b algorithm
mbadhi barnabas
 
Solving N-queen Problem Using Genetic Algorithm by Advance Mutation Operator
Solving N-queen Problem Using Genetic Algorithm by Advance Mutation Operator
IJECEIAES
 
Ai lecture 10(unit02)
Ai lecture 10(unit02)
vikas dhakane
 
N-queens.pptx
N-queens.pptx
anoop2708
 
Backtracking Algorithm.pptx
Backtracking Algorithm.pptx
sangeeta194160
 
8 QUEENS PROBLEM.pptx
8 QUEENS PROBLEM.pptx
sunidhi740916
 
PUZZLE IN C PROGRAMMING
PUZZLE IN C PROGRAMMING
AtchayaaM
 
Puzzle in c program
Puzzle in c program
NabishaAK
 
The N-Queens problemdskksnjfnskjdfnsjnddjsdnjs
The N-Queens problemdskksnjfnskjdfnsjnddjsdnjs
aadarsh4881
 
8 Queens Problemyjjffhhhgfghhhfhhggghjgg
8 Queens Problemyjjffhhhgfghhhfhhggghjgg
hariombhoria70
 
Backtracking Basics.pptx
Backtracking Basics.pptx
sunidhi740916
 
An approach to solve the N-Queens Problem using Artificial Intelligence algor...
An approach to solve the N-Queens Problem using Artificial Intelligence algor...
IRJET Journal
 
module5_backtrackingnbranchnbound_2022.pdf
module5_backtrackingnbranchnbound_2022.pdf
Shiwani Gupta
 
proficiency presenattion on topic of backtracking algo
proficiency presenattion on topic of backtracking algo
sj9399037128
 
Constraint Satisfaction Problem (CSP) by A z m jalal uddin joy_v1.0.1
Constraint Satisfaction Problem (CSP) by A z m jalal uddin joy_v1.0.1
A. Z. M. JALAL UDDIN JOY
 
Genetic Algorithm Artificial Intelligence
Genetic Algorithm Artificial Intelligence
LamisaNoor
 
data structures- back tracking
data structures- back tracking
Abinaya B
 
Solving N-queen Problem Using Genetic Algorithm by Advance Mutation Operator
Solving N-queen Problem Using Genetic Algorithm by Advance Mutation Operator
IJECEIAES
 
Ad

Recently uploaded (20)

What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
Nice Dream.pdf /
Nice Dream.pdf /
ErinUsher3
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
The Man In The Back – Exceptional Delaware.pdf
The Man In The Back – Exceptional Delaware.pdf
dennisongomezk
 
“THE BEST CLASS IN SCHOOL”. _
“THE BEST CLASS IN SCHOOL”. _
Colégio Santa Teresinha
 
2025 June Year 9 Presentation: Subject selection.pptx
2025 June Year 9 Presentation: Subject selection.pptx
mansk2
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
GlysdiEelesor1
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
Plate Tectonic Boundaries and Continental Drift Theory
Plate Tectonic Boundaries and Continental Drift Theory
Marie
 
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Rajdeep Bavaliya
 
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Rajdeep Bavaliya
 
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
RAKESH SAJJAN
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
ICT-8-Module-REVISED-K-10-CURRICULUM.pdf
ICT-8-Module-REVISED-K-10-CURRICULUM.pdf
penafloridaarlyn
 
LDMMIA GRAD Student Check-in Orientation Sampler
LDMMIA GRAD Student Check-in Orientation Sampler
LDM & Mia eStudios
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
Nice Dream.pdf /
Nice Dream.pdf /
ErinUsher3
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
ROLE PLAY: FIRST AID -CPR & RECOVERY POSITION.pptx
Belicia R.S
 
The Man In The Back – Exceptional Delaware.pdf
The Man In The Back – Exceptional Delaware.pdf
dennisongomezk
 
2025 June Year 9 Presentation: Subject selection.pptx
2025 June Year 9 Presentation: Subject selection.pptx
mansk2
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
FIRST DAY HIGH orientation for mapeh subject in grade 10.pptx
GlysdiEelesor1
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
Plate Tectonic Boundaries and Continental Drift Theory
Plate Tectonic Boundaries and Continental Drift Theory
Marie
 
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Paper 109 | Archetypal Journeys in ‘Interstellar’: Exploring Universal Themes...
Rajdeep Bavaliya
 
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Paper 107 | From Watchdog to Lapdog: Ishiguro’s Fiction and the Rise of “Godi...
Rajdeep Bavaliya
 
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
Non-Communicable Diseases and National Health Programs – Unit 10 | B.Sc Nursi...
RAKESH SAJJAN
 
Capitol Doctoral Presentation -June 2025.pptx
Capitol Doctoral Presentation -June 2025.pptx
CapitolTechU
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
ICT-8-Module-REVISED-K-10-CURRICULUM.pdf
ICT-8-Module-REVISED-K-10-CURRICULUM.pdf
penafloridaarlyn
 
LDMMIA GRAD Student Check-in Orientation Sampler
LDMMIA GRAD Student Check-in Orientation Sampler
LDM & Mia eStudios
 
Ad

N Queen Algorithm

  • 1. 1
  • 2. W E L C O M E ! Thank you for coming today! 2
  • 5. 5 N Q u e e n P r o b l e m The N Queen is the problem of placing N chess queens on an N×N chessboard so that no two queens attack each other. For example, following is a solution for 4 Queen problem.
  • 7. V a r i o u s a p p r o a c h e s : 7 Brute force Backtracking Permutation generation Graph theory concepts Divide and conquer approach Mathematical solutions
  • 8. Backtracking Solution : 0 1 2 3 0 1 2 3 0 1 2 3 Positions:
  • 9. 9 F i n a l S o l u t i o n Q Q Q Q
  • 10. Bac k trac k ing Algorithm
  • 11. Backtracking Algorithm : 1) Start from the left most column. 2) If all Queens are placed return true. 3) Try all rows in the current column. Do following for every tried row. a) If the queen can be placed safely in this row then mark this [row, column] as part of the solution and recursively check if placing queen here leads to a solution. b) If placing queen in [row, column] leads to a solution then return true. c) If placing queen doesn't lead to a solution then unmark this [row, column] (Backtrack) and go to step (a) to try other rows. 4) If all rows have been tried and nothing worked, return false to trigger backtracking.
  • 12. T H A N K Y O U ! A N Y Q U E S T I O N S ?

Editor's Notes

  • #4: No slide master