SlideShare a Scribd company logo
1 of 25
TITLE :DATA STRUCTURE AND ALGORITHM
STAF NAME :MS.MANIMOZHI,MCA.,M.PHIL.,(PH.D)
CLASS :III BCA
SEMSTER :V
UNIT :V
.
DATA STRUCTURE AND
ALGORITHM
BACK TRACKING
contents
 Backtracking
 8 queen problem
 4 queen
 Chess board
 Sum of subset
 knapsack
Backtracking
 Backtracking is a general algorithm for finding all (or some)
solutions to some computational problems, notably constraint
satisfaction problems, that incrementally builds candidates to the
solutions, and abandons a candidate ("backtracks") as soon as it
determines that the candidate cannot possibly be completed to a
valid solution.
Backtracking algorithm
Algorithm backtrack(k)
{
For (each x[k],T(x[1]…………x[k-1]do
{
If(bk(x[1],x[2],……x[k]=0)then
{
If(x[1],x[2],……x[k] is a path to an answer node)
Then write (x[1:k];
If(k<n)then backtrack(k+1);
}
}
}
Basics
Examples
 Examples where backtracking can be used to solve puzzles or problems
include:
 Puzzles such as eight queens puzzle, crosswords, verbal
arithmetic, Sudoku, and Peg Solitaire.
 Combinatorial optimization problems such as parsing and the knapsack
problem.
 Logic programming languages such as Icon, Planner and Prolog, which
use backtracking internally to generate answers.
 The following is an example where backtracking is used for the constraint
satisfaction problem
A Sudoku solved by backtracking
Sum of subset
 It is given a n distinct positive numbers
 Desire to find all combinations of these numbers whose sums are m,
 This is called the sum of subsets problem
8 queen problem
 The eight queens puzzle is the problem of placing
eight chess queens on an 8×8 chessboard so that no two queens
threaten each other.
 Thus, a solution requires that no two queens share the same row,
column, or diagonal.
 The eight queens puzzle is an example of the more
general n queens problem of placing n non-attacking queens on
an n×n chessboard, for which solutions exist for all natural
numbers n with the exception of n=2 and n=3.
8 queen problem
Chess board
Can a new queen be placed
Algorithm place(k, i)
{
For j:=1 to k-1 do
If ((x[j]=i)
Then return false;
}
4 queen problem
Graph coloring
 Let g can be graph and m be a given positive integer.
 The nodes of g can be colored in such way that no two adjacent
nodes have the same color yet only m color are used.
 The m colorability optimization problem asks for the smallest
integer m for which the graph g can be colored.
Knapsack problem
 The knapsack problem or rucksack problem is a problem
in combinatorial optimization: Given a set of items, each with a
weight and a value, determine the number of each item to include in
a collection so that the total weight is less than or equal to a given
limit and the total value is as large as possible.
 It derives its name from the problem faced by someone who is
constrained by a fixed-size knapsack and must fill it with the most
valuable items.
Define knapsack
 The most common problem being solved is the 0-1 knapsack problem,
which restricts the number {displaystyle x_{i}} x_{i} of copies of each
kind of item to zero or one. Given a set of n items numbered from 1 up to
n, each with a weight {displaystyle w_{i}} w_{i} and a value
{displaystyle v_{i}} v_{i}, along with a maximum weight capacity W,
 maximize {displaystyle sum _{i=1}^{n}v_{i}x_{i}} sum
_{i=1}^{n}v_{i}x_{i}
 subject to {displaystyle sum _{i=1}^{n}w_{i}x_{i}leq W} sum
_{i=1}^{n}w_{i}x_{i}leq W and {displaystyle x_{i}in {0,1}}
x_{i}in {0,1}.
Knapsack problem algorithms for my real-
life carry-on knapsack
Backtraking pic&amp;def
Backtraking pic&amp;def
Backtraking pic&amp;def

More Related Content

What's hot

Low-rank matrix approximations in Python by Christian Thurau PyData 2014
Low-rank matrix approximations in Python by Christian Thurau PyData 2014Low-rank matrix approximations in Python by Christian Thurau PyData 2014
Low-rank matrix approximations in Python by Christian Thurau PyData 2014PyData
 
Logarithm Bases IA
Logarithm Bases IALogarithm Bases IA
Logarithm Bases IAbank8787
 
Functions revision worksheet (t) part 1
Functions revision worksheet (t)   part 1Functions revision worksheet (t)   part 1
Functions revision worksheet (t) part 1Mishal Chauhan
 
A Survey- Knapsack Problem Using Dynamic Programming
A Survey- Knapsack Problem Using Dynamic ProgrammingA Survey- Knapsack Problem Using Dynamic Programming
A Survey- Knapsack Problem Using Dynamic ProgrammingEditor IJCTER
 
Definite Integrals 8/ Integration by Parts
Definite Integrals 8/ Integration by PartsDefinite Integrals 8/ Integration by Parts
Definite Integrals 8/ Integration by PartsLakshmikanta Satapathy
 
Mathematicalfoundationofcomputerscience
MathematicalfoundationofcomputerscienceMathematicalfoundationofcomputerscience
Mathematicalfoundationofcomputersciencejntuworld
 
Functions revision worksheet (t) part 2
Functions revision worksheet (t)   part 2Functions revision worksheet (t)   part 2
Functions revision worksheet (t) part 2Mishal Chauhan
 
Q paper I puc-2014(MATHEMATICS)
Q paper I puc-2014(MATHEMATICS)Q paper I puc-2014(MATHEMATICS)
Q paper I puc-2014(MATHEMATICS)Bagalkot
 
A Generic Algebraic Model for the Analysis of Cryptographic Key Assignment Sc...
A Generic Algebraic Model for the Analysis of Cryptographic Key Assignment Sc...A Generic Algebraic Model for the Analysis of Cryptographic Key Assignment Sc...
A Generic Algebraic Model for the Analysis of Cryptographic Key Assignment Sc...dhruvgairola
 
Matrices solved ex 3.1
Matrices solved ex   3.1Matrices solved ex   3.1
Matrices solved ex 3.1Ankit Kamboj
 
Set, relation, mapping (t)
Set, relation, mapping (t)  Set, relation, mapping (t)
Set, relation, mapping (t) Mishal Chauhan
 
Hierarchical matrix techniques for maximum likelihood covariance estimation
Hierarchical matrix techniques for maximum likelihood covariance estimationHierarchical matrix techniques for maximum likelihood covariance estimation
Hierarchical matrix techniques for maximum likelihood covariance estimationAlexander Litvinenko
 
2-Rainbow Domination of Hexagonal Mesh Networks
2-Rainbow Domination of Hexagonal Mesh Networks2-Rainbow Domination of Hexagonal Mesh Networks
2-Rainbow Domination of Hexagonal Mesh Networksijcoa
 
II PUC (MATHEMATICS) ANNUAL MODEL QUESTION PAPER FOR ALL SCIENCE STUDENTS WHO...
II PUC (MATHEMATICS) ANNUAL MODEL QUESTION PAPER FOR ALL SCIENCE STUDENTS WHO...II PUC (MATHEMATICS) ANNUAL MODEL QUESTION PAPER FOR ALL SCIENCE STUDENTS WHO...
II PUC (MATHEMATICS) ANNUAL MODEL QUESTION PAPER FOR ALL SCIENCE STUDENTS WHO...Bagalkot
 
Permutation & Combination (t) Part 1
Permutation & Combination (t) Part 1Permutation & Combination (t) Part 1
Permutation & Combination (t) Part 1Mishal Chauhan
 

What's hot (20)

Low-rank matrix approximations in Python by Christian Thurau PyData 2014
Low-rank matrix approximations in Python by Christian Thurau PyData 2014Low-rank matrix approximations in Python by Christian Thurau PyData 2014
Low-rank matrix approximations in Python by Christian Thurau PyData 2014
 
Logarithm Bases IA
Logarithm Bases IALogarithm Bases IA
Logarithm Bases IA
 
Admissible Labelings
Admissible LabelingsAdmissible Labelings
Admissible Labelings
 
Functions revision worksheet (t) part 1
Functions revision worksheet (t)   part 1Functions revision worksheet (t)   part 1
Functions revision worksheet (t) part 1
 
A Survey- Knapsack Problem Using Dynamic Programming
A Survey- Knapsack Problem Using Dynamic ProgrammingA Survey- Knapsack Problem Using Dynamic Programming
A Survey- Knapsack Problem Using Dynamic Programming
 
Definite Integrals 8/ Integration by Parts
Definite Integrals 8/ Integration by PartsDefinite Integrals 8/ Integration by Parts
Definite Integrals 8/ Integration by Parts
 
Exhaustive Combinatorial Enumeration
Exhaustive Combinatorial EnumerationExhaustive Combinatorial Enumeration
Exhaustive Combinatorial Enumeration
 
Mathematicalfoundationofcomputerscience
MathematicalfoundationofcomputerscienceMathematicalfoundationofcomputerscience
Mathematicalfoundationofcomputerscience
 
Functions revision worksheet (t) part 2
Functions revision worksheet (t)   part 2Functions revision worksheet (t)   part 2
Functions revision worksheet (t) part 2
 
Interval Pattern Structures: An introdution
Interval Pattern Structures: An introdutionInterval Pattern Structures: An introdution
Interval Pattern Structures: An introdution
 
3D Geometry QA 5
3D Geometry QA 53D Geometry QA 5
3D Geometry QA 5
 
Q paper I puc-2014(MATHEMATICS)
Q paper I puc-2014(MATHEMATICS)Q paper I puc-2014(MATHEMATICS)
Q paper I puc-2014(MATHEMATICS)
 
A Generic Algebraic Model for the Analysis of Cryptographic Key Assignment Sc...
A Generic Algebraic Model for the Analysis of Cryptographic Key Assignment Sc...A Generic Algebraic Model for the Analysis of Cryptographic Key Assignment Sc...
A Generic Algebraic Model for the Analysis of Cryptographic Key Assignment Sc...
 
Matrices solved ex 3.1
Matrices solved ex   3.1Matrices solved ex   3.1
Matrices solved ex 3.1
 
Set, relation, mapping (t)
Set, relation, mapping (t)  Set, relation, mapping (t)
Set, relation, mapping (t)
 
Hierarchical matrix techniques for maximum likelihood covariance estimation
Hierarchical matrix techniques for maximum likelihood covariance estimationHierarchical matrix techniques for maximum likelihood covariance estimation
Hierarchical matrix techniques for maximum likelihood covariance estimation
 
2-Rainbow Domination of Hexagonal Mesh Networks
2-Rainbow Domination of Hexagonal Mesh Networks2-Rainbow Domination of Hexagonal Mesh Networks
2-Rainbow Domination of Hexagonal Mesh Networks
 
II PUC (MATHEMATICS) ANNUAL MODEL QUESTION PAPER FOR ALL SCIENCE STUDENTS WHO...
II PUC (MATHEMATICS) ANNUAL MODEL QUESTION PAPER FOR ALL SCIENCE STUDENTS WHO...II PUC (MATHEMATICS) ANNUAL MODEL QUESTION PAPER FOR ALL SCIENCE STUDENTS WHO...
II PUC (MATHEMATICS) ANNUAL MODEL QUESTION PAPER FOR ALL SCIENCE STUDENTS WHO...
 
21 backtracking
21 backtracking21 backtracking
21 backtracking
 
Permutation & Combination (t) Part 1
Permutation & Combination (t) Part 1Permutation & Combination (t) Part 1
Permutation & Combination (t) Part 1
 

Similar to Backtraking pic&amp;def

data structure and algorithms Unit 5
data structure and algorithms Unit 5data structure and algorithms Unit 5
data structure and algorithms Unit 5infanciaj
 
5.3 dynamic programming 03
5.3 dynamic programming 035.3 dynamic programming 03
5.3 dynamic programming 03Krish_ver2
 
Perform brute force
Perform brute forcePerform brute force
Perform brute forceSHC
 
Dynamic Programming.pptx
Dynamic Programming.pptxDynamic Programming.pptx
Dynamic Programming.pptxThanga Ramya S
 
Dynamic1
Dynamic1Dynamic1
Dynamic1MyAlome
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesFahim Ferdous
 
Dynamic Programming for 4th sem cse students
Dynamic Programming for 4th sem cse studentsDynamic Programming for 4th sem cse students
Dynamic Programming for 4th sem cse studentsDeepakGowda357858
 
New data structures and algorithms for \\post-processing large data sets and ...
New data structures and algorithms for \\post-processing large data sets and ...New data structures and algorithms for \\post-processing large data sets and ...
New data structures and algorithms for \\post-processing large data sets and ...Alexander Litvinenko
 
Skiena algorithm 2007 lecture15 backtracing
Skiena algorithm 2007 lecture15 backtracingSkiena algorithm 2007 lecture15 backtracing
Skiena algorithm 2007 lecture15 backtracingzukun
 
Linear algebra and vector analysis presentation
Linear algebra and vector analysis presentationLinear algebra and vector analysis presentation
Linear algebra and vector analysis presentationSajibulIslam13
 

Similar to Backtraking pic&amp;def (20)

data structure and algorithms Unit 5
data structure and algorithms Unit 5data structure and algorithms Unit 5
data structure and algorithms Unit 5
 
Unit 3
Unit 3Unit 3
Unit 3
 
Unit 3
Unit 3Unit 3
Unit 3
 
5.3 dynamic programming 03
5.3 dynamic programming 035.3 dynamic programming 03
5.3 dynamic programming 03
 
Perform brute force
Perform brute forcePerform brute force
Perform brute force
 
Lesson 1 matrix
Lesson 1 matrixLesson 1 matrix
Lesson 1 matrix
 
Dynamic Programming.pptx
Dynamic Programming.pptxDynamic Programming.pptx
Dynamic Programming.pptx
 
Dynamic1
Dynamic1Dynamic1
Dynamic1
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
 
Back tracking
Back trackingBack tracking
Back tracking
 
Unit 3-Greedy Method
Unit 3-Greedy MethodUnit 3-Greedy Method
Unit 3-Greedy Method
 
Dynamic Programming for 4th sem cse students
Dynamic Programming for 4th sem cse studentsDynamic Programming for 4th sem cse students
Dynamic Programming for 4th sem cse students
 
New data structures and algorithms for \\post-processing large data sets and ...
New data structures and algorithms for \\post-processing large data sets and ...New data structures and algorithms for \\post-processing large data sets and ...
New data structures and algorithms for \\post-processing large data sets and ...
 
Chapter 16
Chapter 16Chapter 16
Chapter 16
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Skiena algorithm 2007 lecture15 backtracing
Skiena algorithm 2007 lecture15 backtracingSkiena algorithm 2007 lecture15 backtracing
Skiena algorithm 2007 lecture15 backtracing
 
Linear algebra and vector analysis presentation
Linear algebra and vector analysis presentationLinear algebra and vector analysis presentation
Linear algebra and vector analysis presentation
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Unit 4 jwfiles
Unit 4 jwfilesUnit 4 jwfiles
Unit 4 jwfiles
 
Clustering-beamer.pdf
Clustering-beamer.pdfClustering-beamer.pdf
Clustering-beamer.pdf
 

Recently uploaded

Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 

Recently uploaded (20)

Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 

Backtraking pic&amp;def

  • 1. TITLE :DATA STRUCTURE AND ALGORITHM STAF NAME :MS.MANIMOZHI,MCA.,M.PHIL.,(PH.D) CLASS :III BCA SEMSTER :V UNIT :V .
  • 3. contents  Backtracking  8 queen problem  4 queen  Chess board  Sum of subset  knapsack
  • 4. Backtracking  Backtracking is a general algorithm for finding all (or some) solutions to some computational problems, notably constraint satisfaction problems, that incrementally builds candidates to the solutions, and abandons a candidate ("backtracks") as soon as it determines that the candidate cannot possibly be completed to a valid solution.
  • 5. Backtracking algorithm Algorithm backtrack(k) { For (each x[k],T(x[1]…………x[k-1]do { If(bk(x[1],x[2],……x[k]=0)then { If(x[1],x[2],……x[k] is a path to an answer node) Then write (x[1:k]; If(k<n)then backtrack(k+1); } } }
  • 7. Examples  Examples where backtracking can be used to solve puzzles or problems include:  Puzzles such as eight queens puzzle, crosswords, verbal arithmetic, Sudoku, and Peg Solitaire.  Combinatorial optimization problems such as parsing and the knapsack problem.  Logic programming languages such as Icon, Planner and Prolog, which use backtracking internally to generate answers.  The following is an example where backtracking is used for the constraint satisfaction problem
  • 8. A Sudoku solved by backtracking
  • 9. Sum of subset  It is given a n distinct positive numbers  Desire to find all combinations of these numbers whose sums are m,  This is called the sum of subsets problem
  • 10. 8 queen problem  The eight queens puzzle is the problem of placing eight chess queens on an 8×8 chessboard so that no two queens threaten each other.  Thus, a solution requires that no two queens share the same row, column, or diagonal.  The eight queens puzzle is an example of the more general n queens problem of placing n non-attacking queens on an n×n chessboard, for which solutions exist for all natural numbers n with the exception of n=2 and n=3.
  • 13.
  • 14. Can a new queen be placed Algorithm place(k, i) { For j:=1 to k-1 do If ((x[j]=i) Then return false; }
  • 15.
  • 16.
  • 18. Graph coloring  Let g can be graph and m be a given positive integer.  The nodes of g can be colored in such way that no two adjacent nodes have the same color yet only m color are used.  The m colorability optimization problem asks for the smallest integer m for which the graph g can be colored.
  • 19.
  • 20. Knapsack problem  The knapsack problem or rucksack problem is a problem in combinatorial optimization: Given a set of items, each with a weight and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible.  It derives its name from the problem faced by someone who is constrained by a fixed-size knapsack and must fill it with the most valuable items.
  • 21. Define knapsack  The most common problem being solved is the 0-1 knapsack problem, which restricts the number {displaystyle x_{i}} x_{i} of copies of each kind of item to zero or one. Given a set of n items numbered from 1 up to n, each with a weight {displaystyle w_{i}} w_{i} and a value {displaystyle v_{i}} v_{i}, along with a maximum weight capacity W,  maximize {displaystyle sum _{i=1}^{n}v_{i}x_{i}} sum _{i=1}^{n}v_{i}x_{i}  subject to {displaystyle sum _{i=1}^{n}w_{i}x_{i}leq W} sum _{i=1}^{n}w_{i}x_{i}leq W and {displaystyle x_{i}in {0,1}} x_{i}in {0,1}.
  • 22. Knapsack problem algorithms for my real- life carry-on knapsack