SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Backtracking Technique ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Backtracking Technique ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Outline of Backtracking Approach ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],1 2 3 5 7 11 4 6 8 9 10
N-Queens Problem
N-Queens Problem ,[object Object],[object Object],[object Object],Q Q Q Q 1  2  3  4  5  6  7  8 1 2 3 4 5 6 7 8
N-Queens Problem: DFS ,[object Object]
N-Queens Problem: DFS (Same Col/Row x) ,[object Object],X 1 =1 X 2 =2 3 4 4 3 4 3 4 2 3 2 3 2 2 4 3 2 3 4 1 4 1 3 2 4 1 3 4 1 2 4 3 2 1 2 3 4 (x 1 , x 2 , x 3 , x 4 )=(2, 4, 1, 3) ,[object Object],[object Object],[object Object]
N-Queens Problem: Backtracking ,[object Object],[object Object],[object Object],[object Object],Q  (i, col(i)) Q  (k, col(k)) Q (i,col(i)) Q (k,col(k))
N-Queens Problem: Backtracking ,[object Object]
N-Queens Problem ,[object Object],[object Object],[object Object],[object Object],#Nodes Checked DFS   (n n )  #Nodes Checked DFS (same col/row X) (n!) #Nodes Checked Backtracking 341 19,173,961 9.73 ⅹ10 12 1.20ⅹ 10 16 24 40,320 4.79 ⅹ10 8 8.72ⅹ 10 10 61 15,721 1.01 ⅹ10 7 3.78ⅹ 10 8 4 8 12 14 n
Graph Coloring ,[object Object],[object Object],[object Object],[object Object],V 1 V 2 V 4 V 3 2-coloring  X 3-coloring  O
Graph Coloring ,[object Object],[object Object],[object Object],start 1 2 3 2 1 3 2 1 3 2 1 3 X X X X X
Hamiltonian Circuits Problem ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Hamiltonian Circuits Problem ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],HC : X (Eg) V 1 V 2 V 6 V 5 V 3 V 7 V 4 V 8 V 1 V 2 V 5 V 3 V 4
Sum-of-Subsets Problem ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],A w 1 w 2 w 3 w 2 w 3 w 3 w 3 O O O O O O O {w 1 ,w 2 }
Sum-of-Subsets Problem ,[object Object],[object Object],[object Object],[object Object],[object Object],ⅹ 12 7 3 9 7 8 13 4 0 0 3 3 0 4 5 0 0 4 5 5 6 0 0 0 0 ⅹ ⅹ :  0+5+6=11<13 ⅹ ⅹ : 9+6=15>13 ⅹ ⅹ w1=3 w2=4 w3=5 w4=6 0 4 3 7
0-1 Knapsack Problem ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],x 1 =1 x 2 =1 x 3 =1 x 4 =1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 1 1 1 1 1 x 2 =1
Branch-and-Bound ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Breadth First Search ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],BFS of a graph BFS of a tree 1 2 3 4 5 6 7 8 9 1 2 5 6 7 8 9 3 4 10 11 12 13 14 15
0-1 Knapsack Problem ,[object Object],[object Object],0 0 115 40 2 115 0 0 82 70 7 115 40 2 98 120 17 0 70 7 80 80 12 80 70 7 70 90 12 98 40 2 50 100 17 0 90 12 90 30 5 82 80 15 82 30 5 40 0 0 60 p1=40 ,  w1=2 p2=30 ,  w2=5 p3=50 ,  w3=10 p4=10 ,  w4=5
0-1 Knapsack Problem ,[object Object],[object Object],[object Object],0 0 115 40 2 115 0 0 82 70 7 115 40 2 98 120 17 0 70 7 80 80 12 80 70 7 70 90 12 98 40 2 50 100 17 0 90 12 90 30 5 82 80 15 82 30 5 40 0 0 60 p1=40 ,  w1=2 p2=30 ,  w2=5 p3=50 ,  w3=10 p4=10 ,  w4=5
0-1 Knapsack Problem ,[object Object],0 0 115 40 2 115 0 0 82 70 7 115 40 2 98 120 17 0 70 7 80 90 12 98 40 2 50 100 17 0 p1=40 ,  w1=2 p2=30 ,  w2=5 p3=50 ,  w3=10 p4=10 ,  w4=5 90 12 90

Weitere ähnliche Inhalte

Was ist angesagt?

Finite automata examples
Finite automata examplesFinite automata examples
Finite automata examples
ankitamakin
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
Tech_MX
 

Was ist angesagt? (20)

State Space Search in ai
State Space Search in aiState Space Search in ai
State Space Search in ai
 
Finite automata examples
Finite automata examplesFinite automata examples
Finite automata examples
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
 
Greedy algorithms
Greedy algorithmsGreedy algorithms
Greedy algorithms
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Generating code from dags
Generating code from dagsGenerating code from dags
Generating code from dags
 
N queen problem
N queen problemN queen problem
N queen problem
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
 
I.BEST FIRST SEARCH IN AI
I.BEST FIRST SEARCH IN AII.BEST FIRST SEARCH IN AI
I.BEST FIRST SEARCH IN AI
 
Problem reduction AND OR GRAPH & AO* algorithm.ppt
Problem reduction AND OR GRAPH & AO* algorithm.pptProblem reduction AND OR GRAPH & AO* algorithm.ppt
Problem reduction AND OR GRAPH & AO* algorithm.ppt
 
BackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and ExamplesBackTracking Algorithm: Technique and Examples
BackTracking Algorithm: Technique and Examples
 
Dempster shafer theory
Dempster shafer theoryDempster shafer theory
Dempster shafer theory
 
Knapsack problem and Memory Function
Knapsack problem and Memory FunctionKnapsack problem and Memory Function
Knapsack problem and Memory Function
 
AI_Session 7 Greedy Best first search algorithm.pptx
AI_Session 7 Greedy Best first search algorithm.pptxAI_Session 7 Greedy Best first search algorithm.pptx
AI_Session 7 Greedy Best first search algorithm.pptx
 
Np complete
Np completeNp complete
Np complete
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
 
Lecture 3 problem solving
Lecture 3   problem solvingLecture 3   problem solving
Lecture 3 problem solving
 
Problem Formulation in Artificial Inteligence Projects
Problem Formulation in Artificial Inteligence ProjectsProblem Formulation in Artificial Inteligence Projects
Problem Formulation in Artificial Inteligence Projects
 
State Space Representation and Search
State Space Representation and SearchState Space Representation and Search
State Space Representation and Search
 

Andere mochten auch

0 1 knapsack problem using dynamic programming
0 1 knapsack problem using dynamic programming0 1 knapsack problem using dynamic programming
0 1 knapsack problem using dynamic programming
Maher Alshammari
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
Gayathri Gaayu
 

Andere mochten auch (9)

Knapsack
KnapsackKnapsack
Knapsack
 
1 blind search
1 blind search1 blind search
1 blind search
 
Knapsack problem using dynamic programming
Knapsack problem using dynamic programmingKnapsack problem using dynamic programming
Knapsack problem using dynamic programming
 
0 1 knapsack problem using dynamic programming
0 1 knapsack problem using dynamic programming0 1 knapsack problem using dynamic programming
0 1 knapsack problem using dynamic programming
 
Kruskal Algorithm
Kruskal AlgorithmKruskal Algorithm
Kruskal Algorithm
 
Genetic Algorithm based Approach to solve Non-Fractional (0/1) Knapsack Optim...
Genetic Algorithm based Approach to solve Non-Fractional (0/1) Knapsack Optim...Genetic Algorithm based Approach to solve Non-Fractional (0/1) Knapsack Optim...
Genetic Algorithm based Approach to solve Non-Fractional (0/1) Knapsack Optim...
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
 
Knapsack problem
Knapsack problemKnapsack problem
Knapsack problem
 
Knapsack problem using fixed tuple
Knapsack problem using fixed tupleKnapsack problem using fixed tuple
Knapsack problem using fixed tuple
 

Ähnlich wie 01 knapsack using backtracking

Divide-and-Conquer & Dynamic ProgrammingDivide-and-Conqu.docx
Divide-and-Conquer & Dynamic ProgrammingDivide-and-Conqu.docxDivide-and-Conquer & Dynamic ProgrammingDivide-and-Conqu.docx
Divide-and-Conquer & Dynamic ProgrammingDivide-and-Conqu.docx
jacksnathalie
 
Newton Raphson method for load flow analysis
Newton Raphson method for load flow analysisNewton Raphson method for load flow analysis
Newton Raphson method for load flow analysis
divyanshuprakashrock
 

Ähnlich wie 01 knapsack using backtracking (20)

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
 
Disjoint sets
Disjoint setsDisjoint sets
Disjoint sets
 
2018 MUMS Fall Course - Statistical Representation of Model Input (EDITED) - ...
2018 MUMS Fall Course - Statistical Representation of Model Input (EDITED) - ...2018 MUMS Fall Course - Statistical Representation of Model Input (EDITED) - ...
2018 MUMS Fall Course - Statistical Representation of Model Input (EDITED) - ...
 
CS 354 Graphics Math
CS 354 Graphics MathCS 354 Graphics Math
CS 354 Graphics Math
 
Recursion - Computer Algorithms
Recursion - Computer AlgorithmsRecursion - Computer Algorithms
Recursion - Computer Algorithms
 
Dynamic Programming.pptx
Dynamic Programming.pptxDynamic Programming.pptx
Dynamic Programming.pptx
 
Divide-and-Conquer & Dynamic ProgrammingDivide-and-Conqu.docx
Divide-and-Conquer & Dynamic ProgrammingDivide-and-Conqu.docxDivide-and-Conquer & Dynamic ProgrammingDivide-and-Conqu.docx
Divide-and-Conquer & Dynamic ProgrammingDivide-and-Conqu.docx
 
Mathematics 9 Quadratic Functions (Module 1)
Mathematics 9 Quadratic Functions (Module 1)Mathematics 9 Quadratic Functions (Module 1)
Mathematics 9 Quadratic Functions (Module 1)
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Integer_Functions .pdf
Integer_Functions .pdfInteger_Functions .pdf
Integer_Functions .pdf
 
Fast parallelizable scenario-based stochastic optimization
Fast parallelizable scenario-based stochastic optimizationFast parallelizable scenario-based stochastic optimization
Fast parallelizable scenario-based stochastic optimization
 
Module 1 quadratic functions
Module 1   quadratic functionsModule 1   quadratic functions
Module 1 quadratic functions
 
AOA ppt.ppt
AOA ppt.pptAOA ppt.ppt
AOA ppt.ppt
 
Bellman ford
Bellman fordBellman ford
Bellman ford
 
designanalysisalgorithm_unit-v-part2.pptx
designanalysisalgorithm_unit-v-part2.pptxdesignanalysisalgorithm_unit-v-part2.pptx
designanalysisalgorithm_unit-v-part2.pptx
 
Newton Raphson method for load flow analysis
Newton Raphson method for load flow analysisNewton Raphson method for load flow analysis
Newton Raphson method for load flow analysis
 
Daa chpater14
Daa chpater14Daa chpater14
Daa chpater14
 
Polynomials and Curve Fitting in MATLAB
Polynomials and Curve Fitting in MATLABPolynomials and Curve Fitting in MATLAB
Polynomials and Curve Fitting in MATLAB
 
Maths04
Maths04Maths04
Maths04
 
Chapter 04 answers
Chapter 04 answersChapter 04 answers
Chapter 04 answers
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Kürzlich hochgeladen (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 

01 knapsack using backtracking

  • 1.
  • 2.
  • 3.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.