SlideShare a Scribd company logo
BACKTRACKING,GENERAL
METHOD , 8 QUEEN’S PROBLEM
S.Nandhini
II – Msc(CS&IT)
Nadar Saraswathi College Of Arts And Science
Theni.
BACKTRACKING
General method
 Problems searching for a set of solutions or Which
require an optimal solution can be solved using the
backtracking method.
 To apply the backtracking method, the solution must
be expressible as an n- tuple (x1…..xn).
 Where xi are chosen from finite set si.
 The solution vector must satisfy the criterion function
p(x1…….xn).
BACKTRACKING ALGORITHM
EXAMPLE:
Find path through maze
 Start at beginning of maze
 If at exit ,return true
Else for each step from current location
 Recursively Find path
 Return with first successfull step
 Return false if all steps fail
RECURSIVE BACKTRACKING
Pseudo code for recursive backtracking algorithms
If at a solution return success for(every possible choice from
current state/node)
 Make that choice and take one step along path
 Use recursive to solve the problem for the new node/state
 If the recursive call succeeds report the success to the next
high level
 Back out of the current choice to restore the state at the
beginning of the loop.
Report failure
BACKTRACKING ALGORITHM
8 QUEEN’S PROBLEM
 The 8 queens problem puzzle is the problem of
placing eight chess queens an on 8.
 8 chessboard so that no two queens attack each
other.
 Thus a solution requires that no two queens
share the same row, column , diagonal.
 The eight queens puzzle is an example of the
more general n-queens problem of placing n
queens on an n n chessboard.
 Where solution exist for all natural numbers n
with the exception of 1,2 and 3
 The solution possibilities are discovered only up
to 23 queen.
8 QUEEN’S ALGORITHM
All solutions to the n-queens problem
Algorithm NQueens (k,n)
{
For I :=1 to n do
{
If Place( k,i)then
{
X[k]:=I;
If(k=n)then write (x[1:n]);
Else NQueens9(k+1.n);
}
}
}
8 QUEEN’S PROBLEM
FORMULATION:
Status
Any arrangement of 0 to 8 queens on the board
Initial state
0 queens on the board
Successor function
Add a queen in any square
Goal test
8 queens on the board ,none attacked
EXAMPLE 8 QUEENS
1
2
3
4
5
(8,5,4,3,2)=1649
1
2
3
4
5
6
(8,5,3,1,2,1)=769
THANK YOU

More Related Content

What's hot

Graph coloring problem
Graph coloring problemGraph coloring problem
Graph coloring problem
V.V.Vanniaperumal College for Women
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
shashidharPapishetty
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
Dr. C.V. Suresh Babu
 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using Backtracking
Abhishek Singh
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsNikhil Sharma
 
Topological Sort
Topological SortTopological Sort
Topological Sort
Dr Sandeep Kumar Poonia
 
Tsp is NP-Complete
Tsp is NP-CompleteTsp is NP-Complete
Tsp is NP-Complete
Emre Can Kucukoglu
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
Abdullah Al-hazmy
 
SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS
Md. Shafiuzzaman Hira
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
Sukrit Gupta
 
search strategies in artificial intelligence
search strategies in artificial intelligencesearch strategies in artificial intelligence
search strategies in artificial intelligence
Hanif Ullah (Gold Medalist)
 
Stressen's matrix multiplication
Stressen's matrix multiplicationStressen's matrix multiplication
Stressen's matrix multiplicationKumar
 
Three Address code
Three Address code Three Address code
Three Address code
Pooja Dixit
 
Deadlock dbms
Deadlock dbmsDeadlock dbms
Deadlock dbms
Vardhil Patel
 
Lecture 06 production system
Lecture 06 production systemLecture 06 production system
Lecture 06 production system
Hema Kashyap
 
Backtracking
Backtracking  Backtracking
Backtracking
Vikas Sharma
 
Elements of dynamic programming
Elements of dynamic programmingElements of dynamic programming
Elements of dynamic programming
Tafhim Islam
 
Concurrency Control Techniques
Concurrency Control TechniquesConcurrency Control Techniques
Concurrency Control Techniques
Raj vardhan
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsEhtisham Ali
 

What's hot (20)

Graph coloring problem
Graph coloring problemGraph coloring problem
Graph coloring problem
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
 
Randomized algorithms ver 1.0
Randomized algorithms ver 1.0Randomized algorithms ver 1.0
Randomized algorithms ver 1.0
 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using Backtracking
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Topological Sort
Topological SortTopological Sort
Topological Sort
 
Tsp is NP-Complete
Tsp is NP-CompleteTsp is NP-Complete
Tsp is NP-Complete
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
 
SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS SINGLE-SOURCE SHORTEST PATHS
SINGLE-SOURCE SHORTEST PATHS
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
 
search strategies in artificial intelligence
search strategies in artificial intelligencesearch strategies in artificial intelligence
search strategies in artificial intelligence
 
Stressen's matrix multiplication
Stressen's matrix multiplicationStressen's matrix multiplication
Stressen's matrix multiplication
 
Three Address code
Three Address code Three Address code
Three Address code
 
Deadlock dbms
Deadlock dbmsDeadlock dbms
Deadlock dbms
 
Lecture 06 production system
Lecture 06 production systemLecture 06 production system
Lecture 06 production system
 
Backtracking
Backtracking  Backtracking
Backtracking
 
Elements of dynamic programming
Elements of dynamic programmingElements of dynamic programming
Elements of dynamic programming
 
Np cooks theorem
Np cooks theoremNp cooks theorem
Np cooks theorem
 
Concurrency Control Techniques
Concurrency Control TechniquesConcurrency Control Techniques
Concurrency Control Techniques
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 

Similar to data structures- back tracking

8 QUEENS PROBLEM.pptx
8 QUEENS PROBLEM.pptx8 QUEENS PROBLEM.pptx
8 QUEENS PROBLEM.pptx
sunidhi740916
 
backtracking 8 Queen.pptx
backtracking 8 Queen.pptxbacktracking 8 Queen.pptx
backtracking 8 Queen.pptx
JoshipavanEdduluru1
 
N-queens.pptx
N-queens.pptxN-queens.pptx
N-queens.pptx
anoop2708
 
Backtracking Basics.pptx
Backtracking Basics.pptxBacktracking Basics.pptx
Backtracking Basics.pptx
sunidhi740916
 
Backtrack search-algorithm
Backtrack search-algorithmBacktrack search-algorithm
Backtrack search-algorithm
Ruchika Sinha
 
N Queen Algorithm
N Queen AlgorithmN Queen Algorithm
N Queen Algorithm
A.I. Tazib
 
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
varun arora
 
N queen puzzle
N queen puzzleN queen puzzle
N queen puzzle
Akash Sethiya
 
Unit 4 jwfiles
Unit 4 jwfilesUnit 4 jwfiles
Unit 4 jwfiles
Nv Thejaswini
 
8 queen problem
8 queen problem8 queen problem
8 queen problem
NagajothiN1
 
Backtracking Algorithm.pptx
Backtracking Algorithm.pptxBacktracking Algorithm.pptx
Backtracking Algorithm.pptx
sangeeta194160
 
Algorithm Performance For Chessboard Separation Problems
Algorithm Performance For Chessboard Separation ProblemsAlgorithm Performance For Chessboard Separation Problems
Algorithm Performance For Chessboard Separation Problems
Tina Gabel
 
Solution of N Queens Problem genetic algorithm
Solution of N Queens Problem genetic algorithm  Solution of N Queens Problem genetic algorithm
Solution of N Queens Problem genetic algorithm
MohammedAlKazal
 
MASSS_Presentation_20160209
MASSS_Presentation_20160209MASSS_Presentation_20160209
MASSS_Presentation_20160209Yimin Wu
 
Stochastic Process Exam Help
Stochastic Process Exam HelpStochastic Process Exam Help
Stochastic Process Exam Help
Statistics Exam Help
 
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
Philip Schwarz
 
module5_backtrackingnbranchnbound_2022.pdf
module5_backtrackingnbranchnbound_2022.pdfmodule5_backtrackingnbranchnbound_2022.pdf
module5_backtrackingnbranchnbound_2022.pdf
Shiwani Gupta
 
Lecture2b algorithm
Lecture2b algorithmLecture2b algorithm
Lecture2b algorithm
mbadhi barnabas
 

Similar to data structures- back tracking (20)

8 QUEENS PROBLEM.pptx
8 QUEENS PROBLEM.pptx8 QUEENS PROBLEM.pptx
8 QUEENS PROBLEM.pptx
 
backtracking 8 Queen.pptx
backtracking 8 Queen.pptxbacktracking 8 Queen.pptx
backtracking 8 Queen.pptx
 
N-queens.pptx
N-queens.pptxN-queens.pptx
N-queens.pptx
 
Backtracking Basics.pptx
Backtracking Basics.pptxBacktracking Basics.pptx
Backtracking Basics.pptx
 
Backtrack search-algorithm
Backtrack search-algorithmBacktrack search-algorithm
Backtrack search-algorithm
 
algorithm Unit 4
algorithm Unit 4 algorithm Unit 4
algorithm Unit 4
 
N Queen Algorithm
N Queen AlgorithmN Queen Algorithm
N Queen Algorithm
 
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
 
N queen puzzle
N queen puzzleN queen puzzle
N queen puzzle
 
Unit 4 jwfiles
Unit 4 jwfilesUnit 4 jwfiles
Unit 4 jwfiles
 
8 queen problem
8 queen problem8 queen problem
8 queen problem
 
Back tracking
Back trackingBack tracking
Back tracking
 
Backtracking Algorithm.pptx
Backtracking Algorithm.pptxBacktracking Algorithm.pptx
Backtracking Algorithm.pptx
 
Algorithm Performance For Chessboard Separation Problems
Algorithm Performance For Chessboard Separation ProblemsAlgorithm Performance For Chessboard Separation Problems
Algorithm Performance For Chessboard Separation Problems
 
Solution of N Queens Problem genetic algorithm
Solution of N Queens Problem genetic algorithm  Solution of N Queens Problem genetic algorithm
Solution of N Queens Problem genetic algorithm
 
MASSS_Presentation_20160209
MASSS_Presentation_20160209MASSS_Presentation_20160209
MASSS_Presentation_20160209
 
Stochastic Process Exam Help
Stochastic Process Exam HelpStochastic Process Exam Help
Stochastic Process Exam Help
 
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
N-Queens Combinatorial Problem - Polyglot FP for Fun and Profit – Haskell and...
 
module5_backtrackingnbranchnbound_2022.pdf
module5_backtrackingnbranchnbound_2022.pdfmodule5_backtrackingnbranchnbound_2022.pdf
module5_backtrackingnbranchnbound_2022.pdf
 
Lecture2b algorithm
Lecture2b algorithmLecture2b algorithm
Lecture2b algorithm
 

More from Abinaya B

Multimedia
MultimediaMultimedia
Multimedia
Abinaya B
 
Overview of bigdata
Overview of bigdataOverview of bigdata
Overview of bigdata
Abinaya B
 
exception handling in java
exception handling in javaexception handling in java
exception handling in java
Abinaya B
 
data structures
data structuresdata structures
data structures
Abinaya B
 
graphics programming in java
graphics programming in javagraphics programming in java
graphics programming in java
Abinaya B
 
exception handling in java
exception handling in javaexception handling in java
exception handling in java
Abinaya B
 
digital image processing
digital image processingdigital image processing
digital image processing
Abinaya B
 
Image filtering in Digital image processing
Image filtering in Digital image processingImage filtering in Digital image processing
Image filtering in Digital image processing
Abinaya B
 
software engineering
software engineeringsoftware engineering
software engineering
Abinaya B
 
software cost factor
software cost factorsoftware cost factor
software cost factor
Abinaya B
 
Data Mining
Data MiningData Mining
Data Mining
Abinaya B
 
Datamining
DataminingDatamining
Datamining
Abinaya B
 
Basic topic on os
Basic topic on osBasic topic on os
Basic topic on os
Abinaya B
 
Digital principles basic
Digital principles basicDigital principles basic
Digital principles basic
Abinaya B
 
Rdbms1
Rdbms1Rdbms1
Rdbms1
Abinaya B
 
Managing I/O & String function in C
Managing I/O & String function in CManaging I/O & String function in C
Managing I/O & String function in C
Abinaya B
 
Introduction to 80386
Introduction to 80386Introduction to 80386
Introduction to 80386
Abinaya B
 
Network standardization
Network standardizationNetwork standardization
Network standardization
Abinaya B
 

More from Abinaya B (18)

Multimedia
MultimediaMultimedia
Multimedia
 
Overview of bigdata
Overview of bigdataOverview of bigdata
Overview of bigdata
 
exception handling in java
exception handling in javaexception handling in java
exception handling in java
 
data structures
data structuresdata structures
data structures
 
graphics programming in java
graphics programming in javagraphics programming in java
graphics programming in java
 
exception handling in java
exception handling in javaexception handling in java
exception handling in java
 
digital image processing
digital image processingdigital image processing
digital image processing
 
Image filtering in Digital image processing
Image filtering in Digital image processingImage filtering in Digital image processing
Image filtering in Digital image processing
 
software engineering
software engineeringsoftware engineering
software engineering
 
software cost factor
software cost factorsoftware cost factor
software cost factor
 
Data Mining
Data MiningData Mining
Data Mining
 
Datamining
DataminingDatamining
Datamining
 
Basic topic on os
Basic topic on osBasic topic on os
Basic topic on os
 
Digital principles basic
Digital principles basicDigital principles basic
Digital principles basic
 
Rdbms1
Rdbms1Rdbms1
Rdbms1
 
Managing I/O & String function in C
Managing I/O & String function in CManaging I/O & String function in C
Managing I/O & String function in C
 
Introduction to 80386
Introduction to 80386Introduction to 80386
Introduction to 80386
 
Network standardization
Network standardizationNetwork standardization
Network standardization
 

Recently uploaded

Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
JEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questionsJEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questions
ShivajiThube2
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 

Recently uploaded (20)

Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
JEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questionsJEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questions
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 

data structures- back tracking

  • 1. BACKTRACKING,GENERAL METHOD , 8 QUEEN’S PROBLEM S.Nandhini II – Msc(CS&IT) Nadar Saraswathi College Of Arts And Science Theni.
  • 2. BACKTRACKING General method  Problems searching for a set of solutions or Which require an optimal solution can be solved using the backtracking method.  To apply the backtracking method, the solution must be expressible as an n- tuple (x1…..xn).  Where xi are chosen from finite set si.  The solution vector must satisfy the criterion function p(x1…….xn).
  • 3. BACKTRACKING ALGORITHM EXAMPLE: Find path through maze  Start at beginning of maze  If at exit ,return true Else for each step from current location  Recursively Find path  Return with first successfull step  Return false if all steps fail
  • 4. RECURSIVE BACKTRACKING Pseudo code for recursive backtracking algorithms If at a solution return success for(every possible choice from current state/node)  Make that choice and take one step along path  Use recursive to solve the problem for the new node/state  If the recursive call succeeds report the success to the next high level  Back out of the current choice to restore the state at the beginning of the loop. Report failure
  • 6. 8 QUEEN’S PROBLEM  The 8 queens problem puzzle is the problem of placing eight chess queens an on 8.  8 chessboard so that no two queens attack each other.  Thus a solution requires that no two queens share the same row, column , diagonal.  The eight queens puzzle is an example of the more general n-queens problem of placing n queens on an n n chessboard.
  • 7.  Where solution exist for all natural numbers n with the exception of 1,2 and 3  The solution possibilities are discovered only up to 23 queen.
  • 8. 8 QUEEN’S ALGORITHM All solutions to the n-queens problem Algorithm NQueens (k,n) { For I :=1 to n do { If Place( k,i)then { X[k]:=I; If(k=n)then write (x[1:n]); Else NQueens9(k+1.n); } } }
  • 10. FORMULATION: Status Any arrangement of 0 to 8 queens on the board Initial state 0 queens on the board Successor function Add a queen in any square Goal test 8 queens on the board ,none attacked