SlideShare a Scribd company logo
1 of 13
Presented by : G.SRILEKHA
B16CS045
Counsellor : B.SRINIVAS sir
N-QUEENS PROBLEM
CONTENTS
• Problem statement
• History
• Backtracking
• Data flow diagram
• Algorithm
• Output
• Advantages over other methods
• Conclusion
PROBLEM STATEMENT
• The N Queen is the problem of placing N chess
queens on an N×N chessboard so that no two
queens attack each other.
• That means , no two queens are placed in same
row or in same column or diagonal to each other.
HISTORY
• Chess composer Max Bezzel published the eight queens
puzzle in 1848.Franz Nauck published the first solutions
in 1850.Nauck also extended the puzzle to the n queens
problem, with n queens on a chessboard of n × n squares.
• Since then, many mathematicians, including Carl
Friedrich Gauss, have worked on both the eight queens
puzzle and its generalized n-queens version. In
1874, S.Gunther proposed a method using determinants to
find solutions.J.W.L. Glaisher refined Gunther's approach.
BACKTRACKING
• Backtracking is finding the solution of a problem whereby
the solution depends on the previous steps taken.
• Thus, the general steps of backtracking are:
• start with a sub-solution
• check if this sub-solution will lead to the solution or not
• If not, then come back and change the sub-solution and
continue again
startt
Place a Queen and
check for next queen
Is
possi
ble or
not
Backtrack and
again check other
column
stop
No
Yes
FLOW CHART
ALGORITHM
• Place the queens column wise, start from the left most column
• If all queens are placed.
• return true and print the solution.
• Else
• Try all the rows in the current column.
• Check if queen can be placed here safely if yes mark the current cell in
solution matrix as 1 and try to solve the rest of the problem recursively.
• If placing the queen in above step leads to the solution return true.
• If placing the queen in above step does not lead to the solution ,
BACKTRACK, mark the current cell in solution matrix as 0 and return false.
• If all the rows are tried and nothing worked, return false and print NO
SOLUTION.
OUTPUT ( IF N=4)
If we continue the process , we get another solution as :
First Solution
TIME TAKEN FOR EACH INTEGER N OF A QUEEN
ADVANTAGES OVER OTHER METHODS
• The major advantage of the backtracking algorithm is the
abillity to find and count all the possible solutions rather
than just one while offering decent speed. In fact this is
the reason it is so widely used. Also one can easily
produce a parallel version of the backtracking
algorithm increasing speed several times just by starting
multiple threads with different starting positions of the
first queens.
CONCLUSION
• In N-Queen, as N value increases the time of processing
also takes more time .This happens when we try to display
all the possible solutions.
• Of course, we could make it much faster if we wanted to
only find one solution instead of all of them: not more
than a few milliseconds for board sizes up to 50.
THANK YOU !!

More Related Content

What's hot

Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy AlgorithmWaqar Akram
 
Backtracking Algorithm.ppt
Backtracking Algorithm.pptBacktracking Algorithm.ppt
Backtracking Algorithm.pptSalmIbrahimIlyas
 
N Queen Algorithm
N Queen AlgorithmN Queen Algorithm
N Queen AlgorithmA.I. Tazib
 
Travelling salesman dynamic programming
Travelling salesman dynamic programmingTravelling salesman dynamic programming
Travelling salesman dynamic programmingmaharajdey
 
implementation of travelling salesman problem with complexity ppt
implementation of travelling salesman problem with complexity pptimplementation of travelling salesman problem with complexity ppt
implementation of travelling salesman problem with complexity pptAntaraBhattacharya12
 
Constraint satisfaction problems (csp)
Constraint satisfaction problems (csp)   Constraint satisfaction problems (csp)
Constraint satisfaction problems (csp) Archana432045
 
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.pptUNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.pptracha49
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesFahim Ferdous
 
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycleBacktracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cyclevarun arora
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemMadhu Bala
 
01 knapsack using backtracking
01 knapsack using backtracking01 knapsack using backtracking
01 knapsack using backtrackingmandlapure
 
Strassen's matrix multiplication
Strassen's matrix multiplicationStrassen's matrix multiplication
Strassen's matrix multiplicationMegha V
 

What's hot (20)

Greedy Algorithm
Greedy AlgorithmGreedy Algorithm
Greedy Algorithm
 
Backtracking Algorithm.ppt
Backtracking Algorithm.pptBacktracking Algorithm.ppt
Backtracking Algorithm.ppt
 
Backtracking
Backtracking  Backtracking
Backtracking
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
 
N Queen Algorithm
N Queen AlgorithmN Queen Algorithm
N Queen Algorithm
 
Backtracking
BacktrackingBacktracking
Backtracking
 
A* Algorithm
A* AlgorithmA* Algorithm
A* Algorithm
 
Travelling salesman dynamic programming
Travelling salesman dynamic programmingTravelling salesman dynamic programming
Travelling salesman dynamic programming
 
implementation of travelling salesman problem with complexity ppt
implementation of travelling salesman problem with complexity pptimplementation of travelling salesman problem with complexity ppt
implementation of travelling salesman problem with complexity ppt
 
SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 
Constraint satisfaction problems (csp)
Constraint satisfaction problems (csp)   Constraint satisfaction problems (csp)
Constraint satisfaction problems (csp)
 
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.pptUNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.ppt
 
Greedy Algorihm
Greedy AlgorihmGreedy Algorihm
Greedy Algorihm
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycleBacktracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
Backtracking-N Queens Problem-Graph Coloring-Hamiltonian cycle
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
 
01 knapsack using backtracking
01 knapsack using backtracking01 knapsack using backtracking
01 knapsack using backtracking
 
Strassen's matrix multiplication
Strassen's matrix multiplicationStrassen's matrix multiplication
Strassen's matrix multiplication
 

Similar to N-Queens Problem Solved Using Backtracking Algorithm

Backtracking Basics.pptx
Backtracking Basics.pptxBacktracking Basics.pptx
Backtracking Basics.pptxsunidhi740916
 
8 QUEENS PROBLEM.pptx
8 QUEENS PROBLEM.pptx8 QUEENS PROBLEM.pptx
8 QUEENS PROBLEM.pptxsunidhi740916
 
Backtracking Algorithm.pptx
Backtracking Algorithm.pptxBacktracking Algorithm.pptx
Backtracking Algorithm.pptxsangeeta194160
 
N-queens.pptx
N-queens.pptxN-queens.pptx
N-queens.pptxanoop2708
 
module5_backtrackingnbranchnbound_2022.pdf
module5_backtrackingnbranchnbound_2022.pdfmodule5_backtrackingnbranchnbound_2022.pdf
module5_backtrackingnbranchnbound_2022.pdfShiwani Gupta
 
Back tracking and branch and bound class 20
Back tracking and branch and bound class 20Back tracking and branch and bound class 20
Back tracking and branch and bound class 20Kumar
 
Algorithm Performance For Chessboard Separation Problems
Algorithm Performance For Chessboard Separation ProblemsAlgorithm Performance For Chessboard Separation Problems
Algorithm Performance For Chessboard Separation ProblemsTina Gabel
 
Branch and bound
Branch and boundBranch and bound
Branch and boundAcad
 
8-Queens Problem.pptx
8-Queens Problem.pptx8-Queens Problem.pptx
8-Queens Problem.pptxrajinooka
 
bcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptx
bcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptxbcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptx
bcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptxB.T.L.I.T
 
Backtrack search-algorithm
Backtrack search-algorithmBacktrack search-algorithm
Backtrack search-algorithmRuchika Sinha
 
Recursion.pptx
Recursion.pptxRecursion.pptx
Recursion.pptxVijalJain3
 
Constrain satisfaction in artificial intelligence.pptx
Constrain satisfaction in artificial intelligence.pptxConstrain satisfaction in artificial intelligence.pptx
Constrain satisfaction in artificial intelligence.pptxKalpana Mohan
 
MHT Multi Hypothesis Tracking - Part2
MHT Multi Hypothesis Tracking - Part2MHT Multi Hypothesis Tracking - Part2
MHT Multi Hypothesis Tracking - Part2Engin Gul
 

Similar to N-Queens Problem Solved Using Backtracking Algorithm (20)

Backtracking Basics.pptx
Backtracking Basics.pptxBacktracking Basics.pptx
Backtracking Basics.pptx
 
8 QUEENS PROBLEM.pptx
8 QUEENS PROBLEM.pptx8 QUEENS PROBLEM.pptx
8 QUEENS PROBLEM.pptx
 
Backtracking Algorithm.pptx
Backtracking Algorithm.pptxBacktracking Algorithm.pptx
Backtracking Algorithm.pptx
 
N-queens.pptx
N-queens.pptxN-queens.pptx
N-queens.pptx
 
Back tracking
Back trackingBack tracking
Back tracking
 
module5_backtrackingnbranchnbound_2022.pdf
module5_backtrackingnbranchnbound_2022.pdfmodule5_backtrackingnbranchnbound_2022.pdf
module5_backtrackingnbranchnbound_2022.pdf
 
Back tracking and branch and bound class 20
Back tracking and branch and bound class 20Back tracking and branch and bound class 20
Back tracking and branch and bound class 20
 
Algorithm Performance For Chessboard Separation Problems
Algorithm Performance For Chessboard Separation ProblemsAlgorithm Performance For Chessboard Separation Problems
Algorithm Performance For Chessboard Separation Problems
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
 
NP Complete Problems -- Internship
NP Complete Problems -- InternshipNP Complete Problems -- Internship
NP Complete Problems -- Internship
 
8-Queens Problem.pptx
8-Queens Problem.pptx8-Queens Problem.pptx
8-Queens Problem.pptx
 
Stochastic Process Exam Help
Stochastic Process Exam HelpStochastic Process Exam Help
Stochastic Process Exam Help
 
bcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptx
bcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptxbcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptx
bcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptx
 
Stochastic Process Assignment Help
Stochastic Process Assignment HelpStochastic Process Assignment Help
Stochastic Process Assignment Help
 
Backtrack search-algorithm
Backtrack search-algorithmBacktrack search-algorithm
Backtrack search-algorithm
 
Recursion.pptx
Recursion.pptxRecursion.pptx
Recursion.pptx
 
Sudoku
SudokuSudoku
Sudoku
 
Constrain satisfaction in artificial intelligence.pptx
Constrain satisfaction in artificial intelligence.pptxConstrain satisfaction in artificial intelligence.pptx
Constrain satisfaction in artificial intelligence.pptx
 
N Queen Problem
N Queen Problem N Queen Problem
N Queen Problem
 
MHT Multi Hypothesis Tracking - Part2
MHT Multi Hypothesis Tracking - Part2MHT Multi Hypothesis Tracking - Part2
MHT Multi Hypothesis Tracking - Part2
 

Recently uploaded

HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 

Recently uploaded (20)

HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 

N-Queens Problem Solved Using Backtracking Algorithm

  • 1. Presented by : G.SRILEKHA B16CS045 Counsellor : B.SRINIVAS sir N-QUEENS PROBLEM
  • 2. CONTENTS • Problem statement • History • Backtracking • Data flow diagram • Algorithm • Output • Advantages over other methods • Conclusion
  • 3. PROBLEM STATEMENT • The N Queen is the problem of placing N chess queens on an N×N chessboard so that no two queens attack each other. • That means , no two queens are placed in same row or in same column or diagonal to each other.
  • 4. HISTORY • Chess composer Max Bezzel published the eight queens puzzle in 1848.Franz Nauck published the first solutions in 1850.Nauck also extended the puzzle to the n queens problem, with n queens on a chessboard of n × n squares. • Since then, many mathematicians, including Carl Friedrich Gauss, have worked on both the eight queens puzzle and its generalized n-queens version. In 1874, S.Gunther proposed a method using determinants to find solutions.J.W.L. Glaisher refined Gunther's approach.
  • 5. BACKTRACKING • Backtracking is finding the solution of a problem whereby the solution depends on the previous steps taken. • Thus, the general steps of backtracking are: • start with a sub-solution • check if this sub-solution will lead to the solution or not • If not, then come back and change the sub-solution and continue again
  • 6. startt Place a Queen and check for next queen Is possi ble or not Backtrack and again check other column stop No Yes FLOW CHART
  • 7. ALGORITHM • Place the queens column wise, start from the left most column • If all queens are placed. • return true and print the solution. • Else • Try all the rows in the current column. • Check if queen can be placed here safely if yes mark the current cell in solution matrix as 1 and try to solve the rest of the problem recursively. • If placing the queen in above step leads to the solution return true. • If placing the queen in above step does not lead to the solution , BACKTRACK, mark the current cell in solution matrix as 0 and return false. • If all the rows are tried and nothing worked, return false and print NO SOLUTION.
  • 8. OUTPUT ( IF N=4)
  • 9. If we continue the process , we get another solution as : First Solution
  • 10. TIME TAKEN FOR EACH INTEGER N OF A QUEEN
  • 11. ADVANTAGES OVER OTHER METHODS • The major advantage of the backtracking algorithm is the abillity to find and count all the possible solutions rather than just one while offering decent speed. In fact this is the reason it is so widely used. Also one can easily produce a parallel version of the backtracking algorithm increasing speed several times just by starting multiple threads with different starting positions of the first queens.
  • 12. CONCLUSION • In N-Queen, as N value increases the time of processing also takes more time .This happens when we try to display all the possible solutions. • Of course, we could make it much faster if we wanted to only find one solution instead of all of them: not more than a few milliseconds for board sizes up to 50.