SlideShare a Scribd company logo
1 of 21
ALGORITHMS Algorithms
BACKTRACKING
Backtracking is a refinement of the brute force approach, which
systematically searches for a solution to a problem among all
available options. It does so by assuming that the solutions are
represented by vectors (v1,v2, ..., vm) of values and by traversing, in a
depth first manner, the domains of the vectors until the solutions are
found.
When invoked, the algorithm starts with an empty vector. At each
stage it extends the partial vector with a new value. Upon reaching a
partial vector (v1,v2, ..., vi) which can’t represent a partial solution, the
algorithm backtracks by removing the trailing value from the vector,
and then proceeds by trying to extend the vector with alternative
values.
ALGORITHM :
try(v1,v2, ..., vi){
IF (v1,v2, ..., vi) is a solution
THEN RETURN (v1,v2, ..., vi)
FOR each v DO
IF (v1,v2, ..., vi,v) is acceptable vector
THEN sol = try(v1,v2, ..., vi,v)
IF sol ≠ () THEN RETURN sol
END
END
RETURN ()
}
If Si is the domain of vi , then S1 × ... × Sm is the solution space of
the problem. The validity criteria used in checking for acceptable
vectors determines what portion of that space needs to be searched,
and so it also determines the resources required by the algorithm.
The traversal of the solution space can be represented by a depth-
first traversal of a tree. The tree itself is rarely entirely stored by the
algorithm in discourse; instead just a path toward a root is stored, to
enable the backtracking.
1. Traveling Salesperson
The problem assumes a set of n cities, and a salesperson which needs
to visit each city exactly once and return to the base city at the end.
The solution should provide a route of minimal length. The route (a,
b, d, c) is the shortest one for the following one, and its length is 51.
The traveling salesperson problem is an NP-hard problem, and so no
polynomial time algorithm is available for it. Given an instance G =
(V, E) the backtracking algorithm may search for a vector of cities (v1,
..., v|V|) which represents the best route.
The validity criteria may just check for number of cities in of the
routes, pruning out routes longer than |V|. In such a case, the
algorithm needs to investigate |V||V| vectors from the solution space.
On the other hand, the validity criteria may check for repetition of
cities, in which case the number of vectors reduces to |V |!.
THE N QUEENS PROBLEM
Consider a n by n chess board, and the problem of placing n queens
on the board without the queens threatening one another.
The solution space is {1, 2, 3, ..., n}n. The backtracking algorithm may
record the columns where the different queens are positioned. Trying
all vectors (p1, ..., pn) implies nn cases. Noticing that all the queens
must reside in different columns reduces the number of cases to n!.
For the latter case, the root of the traversal tree has degree n, the
children have degree n - 1, the grand children degree n - 2, and so
forth.
The solution space is {1, 2, 3, ..., n}n. The backtracking algorithm may
record the columns where the different queens are positioned. Trying
all vectors (p1, ..., pn) implies nn cases. Noticing that all the queens
must reside in different columns reduces the number of cases to n!.
For the latter case, the root of the traversal tree has degree n, the
children have degree n - 1, the grand children degree n - 2, and so
forth.
GENERATING PERMUTATIONS
A permutation can be obtained by selecting an element in the given
set and recursively permuting the remaining elements.
At each stage of the permutation process, the given set of elements
consists of two parts: a subset of values that already have been
processed, and a subset that still needs to be processed. This logical
separation can be physically realized by exchanging, in the ith step,
the ith value with the value being chosen at that stage. That
approaches leaves the first subset in the first i locations of the
outcome.
permute(i)
{
if i == N output A[N]
else
for j = i to N do
swap(A[i], A[j])
permute(i+1)
swap(A[i], A[j])
}

More Related Content

What's hot

Networks dijkstra's algorithm- pgsr
Networks  dijkstra's algorithm- pgsrNetworks  dijkstra's algorithm- pgsr
Networks dijkstra's algorithm- pgsrLinawati Adiman
 
Pre-Cal 40S March 19, 2009
Pre-Cal 40S March 19, 2009Pre-Cal 40S March 19, 2009
Pre-Cal 40S March 19, 2009Darren Kuropatwa
 
Unit26 shortest pathalgorithm
Unit26 shortest pathalgorithmUnit26 shortest pathalgorithm
Unit26 shortest pathalgorithmmeisamstar
 
Shortest path algorithm
Shortest path algorithmShortest path algorithm
Shortest path algorithmsana younas
 
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
 
MC0082 –Theory of Computer Science
MC0082 –Theory of Computer ScienceMC0082 –Theory of Computer Science
MC0082 –Theory of Computer ScienceAravind NC
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen ProblemSukrit Gupta
 
International Publication - (Calcolo)
International Publication - (Calcolo)International Publication - (Calcolo)
International Publication - (Calcolo)Alberto Auricchio
 
A Biker Travels 60 Miles In 2
A Biker Travels 60 Miles In 2A Biker Travels 60 Miles In 2
A Biker Travels 60 Miles In 2AdvancedAlgebra
 
Dijkstra's algorithm
Dijkstra's algorithmDijkstra's algorithm
Dijkstra's algorithmgsp1294
 
Self Stabilizing Depth-first Search
Self Stabilizing Depth-first SearchSelf Stabilizing Depth-first Search
Self Stabilizing Depth-first SearchIntan Dzikria
 

What's hot (20)

Networks dijkstra's algorithm- pgsr
Networks  dijkstra's algorithm- pgsrNetworks  dijkstra's algorithm- pgsr
Networks dijkstra's algorithm- pgsr
 
Flat
FlatFlat
Flat
 
Pre-Cal 40S March 19, 2009
Pre-Cal 40S March 19, 2009Pre-Cal 40S March 19, 2009
Pre-Cal 40S March 19, 2009
 
25 String Matching
25 String Matching25 String Matching
25 String Matching
 
Fsa
FsaFsa
Fsa
 
Unit26 shortest pathalgorithm
Unit26 shortest pathalgorithmUnit26 shortest pathalgorithm
Unit26 shortest pathalgorithm
 
Dijkstra's Algorithm
Dijkstra's Algorithm Dijkstra's Algorithm
Dijkstra's Algorithm
 
Shortest path algorithm
Shortest path algorithmShortest path algorithm
Shortest path algorithm
 
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
 
(floyd's algm)
(floyd's algm)(floyd's algm)
(floyd's algm)
 
Matlab calculus
Matlab calculusMatlab calculus
Matlab calculus
 
MC0082 –Theory of Computer Science
MC0082 –Theory of Computer ScienceMC0082 –Theory of Computer Science
MC0082 –Theory of Computer Science
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
 
International Publication - (Calcolo)
International Publication - (Calcolo)International Publication - (Calcolo)
International Publication - (Calcolo)
 
A Biker Travels 60 Miles In 2
A Biker Travels 60 Miles In 2A Biker Travels 60 Miles In 2
A Biker Travels 60 Miles In 2
 
Dijkstra's algorithm
Dijkstra's algorithmDijkstra's algorithm
Dijkstra's algorithm
 
Self Stabilizing Depth-first Search
Self Stabilizing Depth-first SearchSelf Stabilizing Depth-first Search
Self Stabilizing Depth-first Search
 
Computer Science Assignment Help
Computer Science Assignment Help Computer Science Assignment Help
Computer Science Assignment Help
 
isomorphism
 isomorphism isomorphism
isomorphism
 
Stochastic matrices
Stochastic matricesStochastic matrices
Stochastic matrices
 

Viewers also liked

17 грудня у білозерській зош і ііі ст
17 грудня у білозерській зош і ііі ст17 грудня у білозерській зош і ііі ст
17 грудня у білозерській зош і ііі стРуслан Симивол
 
Slide share The Ultimate 'Train the Trainers' Service Excellence Learning a...
Slide share   The Ultimate 'Train the Trainers' Service Excellence Learning a...Slide share   The Ultimate 'Train the Trainers' Service Excellence Learning a...
Slide share The Ultimate 'Train the Trainers' Service Excellence Learning a...Dr. Ted Marra
 
Agile project management
Agile project managementAgile project management
Agile project managementmicovi
 
Escasa comprension lectora
Escasa comprension lectoraEscasa comprension lectora
Escasa comprension lectoraflorsitasud
 
Consumo colaborativo na era da Internet - A manifestação do mercado colaborat...
Consumo colaborativo na era da Internet - A manifestação do mercado colaborat...Consumo colaborativo na era da Internet - A manifestação do mercado colaborat...
Consumo colaborativo na era da Internet - A manifestação do mercado colaborat...Louise Carpenedo
 
0525 導入ゼミ 中込優介「ウォークラリーレポート」
0525 導入ゼミ 中込優介「ウォークラリーレポート」0525 導入ゼミ 中込優介「ウォークラリーレポート」
0525 導入ゼミ 中込優介「ウォークラリーレポート」13n1072
 
Ttcn ingenierie protocoles-poly4
Ttcn ingenierie protocoles-poly4Ttcn ingenierie protocoles-poly4
Ttcn ingenierie protocoles-poly4hemanth kumar sonti
 
Catalogo enxebrebooks
Catalogo enxebrebooksCatalogo enxebrebooks
Catalogo enxebrebooksEnxebrebooks
 
Evaluation Question 1 - In what ways does your media product develop or chall...
Evaluation Question 1 - In what ways does your media product develop or chall...Evaluation Question 1 - In what ways does your media product develop or chall...
Evaluation Question 1 - In what ways does your media product develop or chall...29556
 
CV_Martin_VESELY-20160309e
CV_Martin_VESELY-20160309eCV_Martin_VESELY-20160309e
CV_Martin_VESELY-20160309eMartin Vesel
 
Sihma submission refugees_amendment_bill
Sihma submission refugees_amendment_billSihma submission refugees_amendment_bill
Sihma submission refugees_amendment_billSergio Carciotto
 
Jurnal CDIMM_dec 2014_Europe Direct Maramures
Jurnal CDIMM_dec 2014_Europe Direct MaramuresJurnal CDIMM_dec 2014_Europe Direct Maramures
Jurnal CDIMM_dec 2014_Europe Direct MaramuresMargareta Capilnean
 

Viewers also liked (18)

17 грудня у білозерській зош і ііі ст
17 грудня у білозерській зош і ііі ст17 грудня у білозерській зош і ііі ст
17 грудня у білозерській зош і ііі ст
 
Proverbs 27a
Proverbs 27aProverbs 27a
Proverbs 27a
 
Slide share The Ultimate 'Train the Trainers' Service Excellence Learning a...
Slide share   The Ultimate 'Train the Trainers' Service Excellence Learning a...Slide share   The Ultimate 'Train the Trainers' Service Excellence Learning a...
Slide share The Ultimate 'Train the Trainers' Service Excellence Learning a...
 
Agile project management
Agile project managementAgile project management
Agile project management
 
Mophong
MophongMophong
Mophong
 
Enfermedades
Enfermedades Enfermedades
Enfermedades
 
Escasa comprension lectora
Escasa comprension lectoraEscasa comprension lectora
Escasa comprension lectora
 
Consumo colaborativo na era da Internet - A manifestação do mercado colaborat...
Consumo colaborativo na era da Internet - A manifestação do mercado colaborat...Consumo colaborativo na era da Internet - A manifestação do mercado colaborat...
Consumo colaborativo na era da Internet - A manifestação do mercado colaborat...
 
0525 導入ゼミ 中込優介「ウォークラリーレポート」
0525 導入ゼミ 中込優介「ウォークラリーレポート」0525 導入ゼミ 中込優介「ウォークラリーレポート」
0525 導入ゼミ 中込優介「ウォークラリーレポート」
 
Ttcn ingenierie protocoles-poly4
Ttcn ingenierie protocoles-poly4Ttcn ingenierie protocoles-poly4
Ttcn ingenierie protocoles-poly4
 
Dr Zubair Anwar CV
Dr Zubair Anwar CVDr Zubair Anwar CV
Dr Zubair Anwar CV
 
Catalogo enxebrebooks
Catalogo enxebrebooksCatalogo enxebrebooks
Catalogo enxebrebooks
 
Evaluation Question 1 - In what ways does your media product develop or chall...
Evaluation Question 1 - In what ways does your media product develop or chall...Evaluation Question 1 - In what ways does your media product develop or chall...
Evaluation Question 1 - In what ways does your media product develop or chall...
 
Coaching
CoachingCoaching
Coaching
 
CV_Martin_VESELY-20160309e
CV_Martin_VESELY-20160309eCV_Martin_VESELY-20160309e
CV_Martin_VESELY-20160309e
 
Sihma submission refugees_amendment_bill
Sihma submission refugees_amendment_billSihma submission refugees_amendment_bill
Sihma submission refugees_amendment_bill
 
Jurnal CDIMM_dec 2014_Europe Direct Maramures
Jurnal CDIMM_dec 2014_Europe Direct MaramuresJurnal CDIMM_dec 2014_Europe Direct Maramures
Jurnal CDIMM_dec 2014_Europe Direct Maramures
 
Invisible cloak!!
Invisible cloak!!Invisible cloak!!
Invisible cloak!!
 

Similar to Algo

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
 
Lecture_10_Parallel_Algorithms_Part_II.ppt
Lecture_10_Parallel_Algorithms_Part_II.pptLecture_10_Parallel_Algorithms_Part_II.ppt
Lecture_10_Parallel_Algorithms_Part_II.pptWahyuAde4
 
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
 
Numerical
NumericalNumerical
Numerical1821986
 
Optimization problems
Optimization problemsOptimization problems
Optimization problemsRuchika Sinha
 
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.pptParallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.pptBinayakMukherjee4
 
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWERUndecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWERmuthukrishnavinayaga
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesFahim Ferdous
 

Similar to Algo (20)

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
 
Chap04alg
Chap04algChap04alg
Chap04alg
 
Chap04alg
Chap04algChap04alg
Chap04alg
 
Lecture_10_Parallel_Algorithms_Part_II.ppt
Lecture_10_Parallel_Algorithms_Part_II.pptLecture_10_Parallel_Algorithms_Part_II.ppt
Lecture_10_Parallel_Algorithms_Part_II.ppt
 
Daa chapter11
Daa chapter11Daa chapter11
Daa chapter11
 
Brute force
Brute forceBrute force
Brute force
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Unit 4 jwfiles
Unit 4 jwfilesUnit 4 jwfiles
Unit 4 jwfiles
 
backtracking 8 Queen.pptx
backtracking 8 Queen.pptxbacktracking 8 Queen.pptx
backtracking 8 Queen.pptx
 
algorithm Unit 4
algorithm Unit 4 algorithm Unit 4
algorithm Unit 4
 
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...
 
Numerical
NumericalNumerical
Numerical
 
Svm vs ls svm
Svm vs ls svmSvm vs ls svm
Svm vs ls svm
 
Parallel algorithm in linear algebra
Parallel algorithm in linear algebraParallel algorithm in linear algebra
Parallel algorithm in linear algebra
 
Optimization problems
Optimization problemsOptimization problems
Optimization problems
 
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.pptParallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
Parallel_Algorithms_In_Combinatorial_Optimization_Problems.ppt
 
Solution 3.
Solution 3.Solution 3.
Solution 3.
 
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWERUndecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
 
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
 

More from Raghu nath

Ftp (file transfer protocol)
Ftp (file transfer protocol)Ftp (file transfer protocol)
Ftp (file transfer protocol)Raghu nath
 
Javascript part1
Javascript part1Javascript part1
Javascript part1Raghu nath
 
Regular expressions
Regular expressionsRegular expressions
Regular expressionsRaghu nath
 
Selection sort
Selection sortSelection sort
Selection sortRaghu nath
 
Binary search
Binary search Binary search
Binary search Raghu nath
 
JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)Raghu nath
 
Stemming algorithms
Stemming algorithmsStemming algorithms
Stemming algorithmsRaghu nath
 
Step by step guide to install dhcp role
Step by step guide to install dhcp roleStep by step guide to install dhcp role
Step by step guide to install dhcp roleRaghu nath
 
Network essentials chapter 4
Network essentials  chapter 4Network essentials  chapter 4
Network essentials chapter 4Raghu nath
 
Network essentials chapter 3
Network essentials  chapter 3Network essentials  chapter 3
Network essentials chapter 3Raghu nath
 
Network essentials chapter 2
Network essentials  chapter 2Network essentials  chapter 2
Network essentials chapter 2Raghu nath
 
Network essentials - chapter 1
Network essentials - chapter 1Network essentials - chapter 1
Network essentials - chapter 1Raghu nath
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2Raghu nath
 
python chapter 1
python chapter 1python chapter 1
python chapter 1Raghu nath
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell ScriptingRaghu nath
 

More from Raghu nath (20)

Mongo db
Mongo dbMongo db
Mongo db
 
Ftp (file transfer protocol)
Ftp (file transfer protocol)Ftp (file transfer protocol)
Ftp (file transfer protocol)
 
MS WORD 2013
MS WORD 2013MS WORD 2013
MS WORD 2013
 
Msword
MswordMsword
Msword
 
Ms word
Ms wordMs word
Ms word
 
Javascript part1
Javascript part1Javascript part1
Javascript part1
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Selection sort
Selection sortSelection sort
Selection sort
 
Binary search
Binary search Binary search
Binary search
 
JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)
 
Stemming algorithms
Stemming algorithmsStemming algorithms
Stemming algorithms
 
Step by step guide to install dhcp role
Step by step guide to install dhcp roleStep by step guide to install dhcp role
Step by step guide to install dhcp role
 
Network essentials chapter 4
Network essentials  chapter 4Network essentials  chapter 4
Network essentials chapter 4
 
Network essentials chapter 3
Network essentials  chapter 3Network essentials  chapter 3
Network essentials chapter 3
 
Network essentials chapter 2
Network essentials  chapter 2Network essentials  chapter 2
Network essentials chapter 2
 
Network essentials - chapter 1
Network essentials - chapter 1Network essentials - chapter 1
Network essentials - chapter 1
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2
 
python chapter 1
python chapter 1python chapter 1
python chapter 1
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell Scripting
 
Perl
PerlPerl
Perl
 

Recently uploaded

Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxRosabel UA
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 

Recently uploaded (20)

Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 

Algo

  • 2. BACKTRACKING Backtracking is a refinement of the brute force approach, which systematically searches for a solution to a problem among all available options. It does so by assuming that the solutions are represented by vectors (v1,v2, ..., vm) of values and by traversing, in a depth first manner, the domains of the vectors until the solutions are found. When invoked, the algorithm starts with an empty vector. At each stage it extends the partial vector with a new value. Upon reaching a partial vector (v1,v2, ..., vi) which can’t represent a partial solution, the algorithm backtracks by removing the trailing value from the vector, and then proceeds by trying to extend the vector with alternative values.
  • 3. ALGORITHM : try(v1,v2, ..., vi){ IF (v1,v2, ..., vi) is a solution THEN RETURN (v1,v2, ..., vi) FOR each v DO IF (v1,v2, ..., vi,v) is acceptable vector THEN sol = try(v1,v2, ..., vi,v) IF sol ≠ () THEN RETURN sol END END RETURN () }
  • 4. If Si is the domain of vi , then S1 × ... × Sm is the solution space of the problem. The validity criteria used in checking for acceptable vectors determines what portion of that space needs to be searched, and so it also determines the resources required by the algorithm. The traversal of the solution space can be represented by a depth- first traversal of a tree. The tree itself is rarely entirely stored by the algorithm in discourse; instead just a path toward a root is stored, to enable the backtracking.
  • 5.
  • 6. 1. Traveling Salesperson The problem assumes a set of n cities, and a salesperson which needs to visit each city exactly once and return to the base city at the end. The solution should provide a route of minimal length. The route (a, b, d, c) is the shortest one for the following one, and its length is 51.
  • 7.
  • 8. The traveling salesperson problem is an NP-hard problem, and so no polynomial time algorithm is available for it. Given an instance G = (V, E) the backtracking algorithm may search for a vector of cities (v1, ..., v|V|) which represents the best route. The validity criteria may just check for number of cities in of the routes, pruning out routes longer than |V|. In such a case, the algorithm needs to investigate |V||V| vectors from the solution space.
  • 9.
  • 10.
  • 11. On the other hand, the validity criteria may check for repetition of cities, in which case the number of vectors reduces to |V |!.
  • 12.
  • 13. THE N QUEENS PROBLEM Consider a n by n chess board, and the problem of placing n queens on the board without the queens threatening one another. The solution space is {1, 2, 3, ..., n}n. The backtracking algorithm may record the columns where the different queens are positioned. Trying all vectors (p1, ..., pn) implies nn cases. Noticing that all the queens must reside in different columns reduces the number of cases to n!. For the latter case, the root of the traversal tree has degree n, the children have degree n - 1, the grand children degree n - 2, and so forth.
  • 14.
  • 15. The solution space is {1, 2, 3, ..., n}n. The backtracking algorithm may record the columns where the different queens are positioned. Trying all vectors (p1, ..., pn) implies nn cases. Noticing that all the queens must reside in different columns reduces the number of cases to n!. For the latter case, the root of the traversal tree has degree n, the children have degree n - 1, the grand children degree n - 2, and so forth.
  • 16.
  • 17. GENERATING PERMUTATIONS A permutation can be obtained by selecting an element in the given set and recursively permuting the remaining elements.
  • 18.
  • 19. At each stage of the permutation process, the given set of elements consists of two parts: a subset of values that already have been processed, and a subset that still needs to be processed. This logical separation can be physically realized by exchanging, in the ith step, the ith value with the value being chosen at that stage. That approaches leaves the first subset in the first i locations of the outcome.
  • 20.
  • 21. permute(i) { if i == N output A[N] else for j = i to N do swap(A[i], A[j]) permute(i+1) swap(A[i], A[j]) }