SlideShare ist ein Scribd-Unternehmen logo
1 von 34
Downloaden Sie, um offline zu lesen
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 backtrack method, the solution must
                be expressible as an n-tuple(x1,…,xn), where the
                xi are chosen from some finite set si
              • The solution vector must satisfy the criterion
                function P(x1 , ….. , xn).
                                                                                               1



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
BACKTRACKING (Contd..)
                • Suppose there are m n-tuples which are
                  possible candidates for satisfying the
                  function P.
                • Then m= m1, m2…..mn where mi is size of
                  set si 1<=i<=n.
                • The brute force approach would be to form
                  all of these n-tuples and evaluate each one
                  with P, saving the optimum.

                                                                                               2



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
BACKTRACKING (Contd..)
                • The backtracking algorithm has the ability to yield
                  the same answer with far fewer than m-trials.
                • In backtracking, the solution is built one
                  component at a time.
                • Modified criterion functions Pi (x1...xn) called
                  bounding functions are used to test whether the
                  partial vector (x1,x2,......,xi) can lead to an optimal
                  solution.
                • If (x1,...xi) is not leading to a solution, mi+1,....,mn
                  possible test vectors may be ignored.                  3



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
BACKTRACKING (Contd..)
                • The constraints may be of two categories.
                • EXPLICIT CONSTRAINTS are rules which restrict the
                  values of xi. Examples xi  0 or x1= 0 or 1 or li  xi  ui.
                • All tuples that satisfy the explicit constraints define a
                  possible solution space for I.
                • IMPLICIT CONSTRAINTS describe the way in which
                  the xi must relate to each other .
                • Implicit constraints allow to find those tuples in the
                  solution space that satisfy the criterion function.


                                                                                               4



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
Example : 8 queens problem
                • The problem is to place eight queens on an 8 x 8
                  chess board so that no two queens attack i.e. no two
                  of them are on the same row, column or diagonal.
                • Strategy : The rows and columns are numbered
                  through 1 to 8.
                • The queens are also numbered through 1 to 8.
                • Since each queen is to be on a different row
                  without loss of generality, we assume queen i is to
                  be placed on row i .
                                                                                               5



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
8 queens problem (Contd..)

                • The solution is an 8 tuple (x1,x2,.....,x8)
                  where xi is the column on which queen i is
                  placed.
                • The explicit constraints are :
                   Si = {1,2,3,4,5,6,7,8} 1  i  n or 1  xi  8
                  i = 1,.........8
                • The solution space consists of 88 8- tuples.

                                                                                               6



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
8 queens problem (Contd..)

                The implicit constraints are :
                (i) no two xis can be the same that is, all queens
                     must be on different columns.
                (ii) no two queens can be on the same diagonal.
                (i) reduces the size of solution space from 88 to 8!
                    8 – tuples.
                     Two solutions are (4,6,8,2,7,1,3,5) and
                     (3,8,4,7,1,6,2,5)
                                                                                               7



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
8 queens problem (Contd..)


                                     1            2            3           4           5       6   7   8
                          1                                                Q
                          2                                                                    Q
                          3                                                                            Q
                          4                       Q
                          5                                                                        Q
                          6          Q
                          7                                    Q
                          8                                                            Q                   8



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
State space tree representation
                Solution Space :
                • Tuples that satisfy the explicit constraints define a solution
                  space.
                • The solution space can be organized into a tree.
                • Each node in the tree defines a problem state.
                • All paths from the root to other nodes define the state-
                  space of the problem.
                • Solution states are those states leading to a tuple in the
                  solution space.
                • Answer nodes are those solution states leading to an
                  answer-tuple( i.e. tuples which satisfy implicit constraints).
                                                                                               9



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
State space tree representation contd..

                • The problem may be solved by systematically
                  generating the problem states determining which
                  are solution states, and determining the answer
                  states.
                • Let us see the following terminology
                • LIVE NODE A node which has been generated
                  and all of whose children are not yet been
                  generated .
                • E-NODE (Node being expanded) - The live node
                  whose children are currently being generated .

                                                                                               10



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
State space tree representation contd..

                • DEAD NODE - A node that is either not to
                  be expanded further, or for which all of its
                  children have been generated.
                • DEPTH FIRST NODE GENERATION- In
                  this, as soon as a new child C of the current
                  E-node R is generated, C will become the
                  new E-node.
                  R will become E-node again when C has
                  been fully explored.
                                                                                               11



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
State space tree representation contd..

                • BOUNDING FUNCTION - will be used to
                  kill live nodes without generating all their
                  children.
                • BACTRACKING-is depth – first node
                  generation with bounding functions.
                • BRANCH-and-BOUND is a method in
                  which E-node remains E-node until it is
                  dead.

                                                                                               12



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
State space tree representation contd..

                • BREADTH-FIRST-SEARCH : Branch-and
                  Bound with each new node placed in a
                  queue .
                  The front of the queen becomes the new E-
                  node.
                • DEPTH-SEARCH (D-Search) : New nodes
                  are placed in to a stack.
                  The last node added is the first to be
                  explored.
                                                                                               13



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
Example : 4 Queens problem


             1                                     1                                  1            1
                                                   .        .         2                        2                    2
                                                                                                       3
                                                                                                   .   .   .        .

                       1                                     1
                                                                               2
                                                   3
                                                   .        .        4
                                                                                                               14



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
State space tree: 4 Queens problem

                                                                               1
                                                      x1 = 1                   x1=2
                                                          2                  18
                                      x2=2             3      4       x2=1 x2=3                x2 = 4
                                       B 3                8     13    19        24             29
                            x3=3                         x3=4 2     3 B          B
                                          4           6      14    16                               x3 = 1
                       x4=4                                3       B                           30
                                         5            7      15                                   x4 = 3
                                                              B                                  31
                                                                                                        15



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
State space tree: 4 Queens problem contd..

                • If (x1….xi) is the path to the current E-node
                  , a bounding function has the criterion that
                  (x1..xi+1)    represents     a     chessboard
                  configuration, in which no queens are
                  attacking.
                • A node that gets killed as a result of the
                  bounding function has a B under it.

                                                                                               16



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
State space tree: 4 Queens problem contd..

                • We start with root node as the only live node. The
                  path is ( ); we generate a child node 2.
                • The path is (1).This corresponds to placing queen
                  1 on column 1 .
                • Node 2 becomes the E node. Node 3 is generated
                  and immediately killed. (because x1=1,x2=2).
                • As node 3 is killed, nodes 4,5,6,7 need not be
                  generated.

                                                                                               17



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
State space tree: 4 Queens problem contd..
                             • Node 8 is generated, and the path is (1,3).
                             • Node 8 gets killed as all its children
                               represent board configurations that cannot
                               lead to answer. We backtrack to node 2 and
                               generate another child node 13.
                             • But the path (1,4) cannot lead to answer
                               nodes.
                             • So , we backtrack to 1 and generate the
                               path (2) with node 18. We observe that the
                               path to answer node is (2 4 1 3 )
                             • Other solution is (3, 1, 4, 2)
                                                                                               18



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
GENERAL BACKTRACKING METHOD

                • All answer nodes are to be found
                • If (x1…..xi) is a path from root to a node then T
                  (x1,….,xi) be the set of all possible values for Xi+1,
                  such that (x1,x2,…….,xi,xi+1) is also a path from
                  root to a problem state.
                • B(x1…xi+1) or Bxi+1is false for the path (x1,..,xi+1)
                  if the path cannot reach an answer node.
                • The solution vectors X (1: n) are those values
                  which are generated by T and satisfy Bi+1.

                                                                                               19



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
GENERAL BACKTRACKING METHOD
                           (Contd..)
              Procedure backtrack (n) // solution vectors are X(1:n)//
                              // and printed as soon as generated //
              // T {X(1),….X(k-1)} gives all possible values of X(k)
              // given that X(1),…..,X(k-1) have already been chosen //
              // The predicates Bk (X(1),….X(k) ) determine those
                  elements //
              // which satisfy the implicit constraints //
              // Implicit constraints are “no two X is can be the same” //
              Integer k, n; local X (1:n)

                                                                                               20



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
GENERAL BACKTRACKING METHOD (Contd..)
            K 1
            while K <> 0 do
            if there remained an untried X(k) such that X(k) 
            T ( X (1) , …..X(k-1) ) and Bk (X (1) ,…,X(k) ) = true then

              if (X (1),…, X(k) ) is a path to an answer node then
                         print ( X (1) ,…X (k) ) // and proceed for another//
                                        //solution with untried value of X(k)//
                 K K+1 // consider next set//
             endif // end of if there remained ….//

            else K K-1 // backtrack to previous component as no value of X(k)
                      //satisfies the constraints//
            endif
            repeat
            end Backtrack


                                                                                               21



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
EXAMPLE OF ALGORITHM WITH
                    4 QUEENS PROBLEMS
                       k 1
                loop 1 X0 =1,1 {1,2,3,4} and B1 (X (1)) = true
                1 is not a path to answer node
                K  1+1=2
                repeat K 2
                loop 2
                   X(2){2,3,4}and B2 (1,2) is False but there
                   remains untried X(k)=3 and X(K) =4
                                                                                               22



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
EXAMPLE OF ALGORITHM WITH
                 4 QUEENS PROBLEMS (Contd..)
                B2 (1,3)=true , but (1,3) Is not a path to
                answer node ; so K K+1=3
                There is no X(3) such that
                B3(1,3,2) or B3 (1,3,4) is true .
                So backtrack K K-1=2
                consider X (2)  4

                                                                                               23



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
EXAMPLE OF ALGORITHM WITH
                 4 QUEENS PROBLEMS (Contd..)
                  (1,4) is not a path to answer
                  (1,4,2) is not a path to answer
                  B4(1,4,2,3)=false.
                  Thus X(2)=4 is false
                  With X(1)=1, we have seen that there is no X(2)
                  satisfying the constraints so KK-1=2-1=1
                  There remained untried X(k)=2,3,4.
                  Repeating with X(1)=2, we observe (2,4,1, 3) is a path to an
                     answer node .
                  Similarly the other solution is (3,1,4,2)

                                                                                               24



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
BACKTRACKING ALGORITHM WITH
                                 RECURSION
                 Procedure RBACKTRACK (k)
                 // on entering the first K-1 values X(1),…..,X(k-1)//
                 // of the solution vector X(1:n) have been assigned //
                 global n , X(1:n)
                 for each X(k) such that
                 X(k)  T ( X (1),..X(k-1) ) Do
                 if Bk (X(1)..,X(k-1), X(k) )= true then {
                 if ( X (1) ,….,X(k) ) is a path to an answer node
                 then print ( X(1),……,X(k) ) endif
              if (k<n)
             CALL RBACKTRACK (k+1)
              endif }// end of if Bk (X(1)…//
              repeat // end of for each X(k)…//
             end RBACKTRACK                                                                    25



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
BACKTRACKING ALGORITHM WITH
                       RECURSION (Contd..)

                EXAMPLE (RB – RBACKTRACK)
                Initially RB(1) is called
                for each X(1)  X(1) {1,2,3,4} and B1 (1) is
                true , but 1 is not an answer node.
                RB (2) is called
                X(2) {2,3,4} and B2 (1,3) = true and B2 (1,4) = true
                (1,3) is not an answer node , RB(3) is called,X(3) = 2,

                                                                                               26



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
BACKTRACKING ALGORITHM WITH
                       RECURSION (Contd..)
                     but (1,3,2) is not Answer node , so , RB(4) is
                     called B4 (1,3,2,4) = false.
                     (1,3,4,2) is not bounded so , X(2) = 4 is tried
                     (1,4,2,3) is not bounded . With X(1)=1 no solution
                     Now for X(1) = 2,3,4 repeat
                     (2,4,1,3) is an answer node, other paths with X(1)
                     = 2 are not leading to answer node.
                     With X (1) = 3 , (3,1,4,2) is an answer node.
                     X (1) = 4 - no solution.
                                                                                               27



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
EFFICIENCY OF BACKTRACKING (BT)
                       ALGORITHM

                • The time required by a backtracking algorithm or the
                  efficiency depends on four factors
                  (i) The time to generate the next X(k);
                  (ii) The number of X(k) satisfying the explicit
                  constraints
                  (iii) The time for bounding functions Bi
                  (iv) The number of X(k) satisfying the Bi for all i.


                                                                                               28



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
EFFICIENCY OF BACKTRACKING
                     ALGORITHM (Contd..)
                • The first three are relatively independent of
                  the problem instance being solved.
                • The complexity for the first three is of
                  polynomial complexity .
                • If the number of nodes generated is 2n , then
                  the worst case complexity for a
                  backtracking algorithm is O(P(n)2n) where
                  P(n) is a polynomial in n .

                                                                                               29



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
Estimation Of Nodes generated in a
                                 BT Algorithm
                • Generate a random path in the state space tree.
                • Let X be a node at level i on this path.
                • Let mi be the children of X ( at level i+1 ) that do
                  not get bounded. (i.e. mi are the nodes which can
                  be considered for getting an answer node ).
                • Choose randomly one of the mi.
                • Continue this until this node is either is a leaf or
                  all its children are bounded.

                                                                                               30



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
Estimation of Nodes generated in a
                           BT Algorithm (Contd..)
                               • Let m be the no. of unbounded nodes to be
                                 generated.
                               • Let us assume that the bounding functions
                                 are static, i.e., the BT algorithm does not
                                 change its bounding functions.
                               • The number of estimated number of
                                 unbounded nodes
                                =1+m1+m1m2+….. +m1m2m3..mi where mi is
                                 the estimated no. of nodes at level i+ 1.

                                                                                               31



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
Estimation of Nodes generated in a
                            BT Algorithm (Contd..)
                               • The number of unbounded nodes on level one
                                 is 1.
                               • The number of unbounded nodes on level 2 is
                                 m1
                               • The total no. of nodes generated till level 2 is
                                 1 + m1
                                The total number of nodes generated till level
                                 i+1 is 1+m1+…+m1…mi .
                       – The above procedure can be written as an algorithm.

                                                                                               32



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
Estimation of Nodes generated in a BTAlgorithm (Contd..)
                               Procedure Estimate
                               // This procedure follows a random path and estimates//
                               // number of unbounded nodes //
                               m1; r1; k1
                               loop
                                  Tk {X (k): X(k) T ( X(1) ,….X(k-1)) and Bk (X (1), ….,
                                  X(k)) is TRUE}
                                  If size (Tk) = 0 then exit endif // SIZE returns the //
                                  r  r * SIZE (Tk)               // size of the set Tk //
                                  m  m+r
                               X (k)  CHOOSE (Tk) // CHOOSE makes a random
                                                         choice of an element in Tk //
                                    k k+1
                                repeat
                                return (m)
                              end estimate
                                                                                               33



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
The n-queens problem and solution


                • In implementing the n – queens problem we
                  imagine the chessboard as a two-
                  dimensional array A (1 : n, 1 : n).
                • The condition to test whether two queens, at
                  positions (i, j) and (k, l) are on the same row
                  or column is simply to check i = k or j = l


                                                                                               34



Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)

Weitere ähnliche Inhalte

Was ist angesagt?

The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen ProblemSukrit Gupta
 
File models and file accessing models
File models and file accessing modelsFile models and file accessing models
File models and file accessing modelsishmecse13
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back trackingTech_MX
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemMadhu Bala
 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using BacktrackingAbhishek Singh
 
distributed shared memory
 distributed shared memory distributed shared memory
distributed shared memoryAshish Kumar
 
Back tracking and branch and bound class 20
Back tracking and branch and bound class 20Back tracking and branch and bound class 20
Back tracking and branch and bound class 20Kumar
 
Knapsack problem using greedy approach
Knapsack problem using greedy approachKnapsack problem using greedy approach
Knapsack problem using greedy approachpadmeshagrekar
 
01 knapsack using backtracking
01 knapsack using backtracking01 knapsack using backtracking
01 knapsack using backtrackingmandlapure
 
Traveling salesman problem
Traveling salesman problemTraveling salesman problem
Traveling salesman problemJayesh Chauhan
 
Agreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemoryAgreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemorySHIKHA GAUTAM
 
Distributed shred memory architecture
Distributed shred memory architectureDistributed shred memory architecture
Distributed shred memory architectureMaulik Togadiya
 

Was ist angesagt? (20)

The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
 
Sum of subset problem.pptx
Sum of subset problem.pptxSum of subset problem.pptx
Sum of subset problem.pptx
 
File models and file accessing models
File models and file accessing modelsFile models and file accessing models
File models and file accessing models
 
Data Structure and Algorithm - Divide and Conquer
Data Structure and Algorithm - Divide and ConquerData Structure and Algorithm - Divide and Conquer
Data Structure and Algorithm - Divide and Conquer
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
 
8 queen problem
8 queen problem8 queen problem
8 queen problem
 
Backtracking
Backtracking  Backtracking
Backtracking
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
 
sum of subset problem using Backtracking
sum of subset problem using Backtrackingsum of subset problem using Backtracking
sum of subset problem using Backtracking
 
Sliding window protocol
Sliding window protocolSliding window protocol
Sliding window protocol
 
distributed shared memory
 distributed shared memory distributed shared memory
distributed shared memory
 
Knapsack Problem
Knapsack ProblemKnapsack Problem
Knapsack Problem
 
Back tracking and branch and bound class 20
Back tracking and branch and bound class 20Back tracking and branch and bound class 20
Back tracking and branch and bound class 20
 
Knapsack problem using greedy approach
Knapsack problem using greedy approachKnapsack problem using greedy approach
Knapsack problem using greedy approach
 
Backtracking
BacktrackingBacktracking
Backtracking
 
Distributed Operating System_1
Distributed Operating System_1Distributed Operating System_1
Distributed Operating System_1
 
01 knapsack using backtracking
01 knapsack using backtracking01 knapsack using backtracking
01 knapsack using backtracking
 
Traveling salesman problem
Traveling salesman problemTraveling salesman problem
Traveling salesman problem
 
Agreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemoryAgreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared Memory
 
Distributed shred memory architecture
Distributed shred memory architectureDistributed shred memory architecture
Distributed shred memory architecture
 

Ähnlich wie backtracking algorithms of ada

Chris Dyer - 2017 - Neural MT Workshop Invited Talk: The Neural Noisy Channel...
Chris Dyer - 2017 - Neural MT Workshop Invited Talk: The Neural Noisy Channel...Chris Dyer - 2017 - Neural MT Workshop Invited Talk: The Neural Noisy Channel...
Chris Dyer - 2017 - Neural MT Workshop Invited Talk: The Neural Noisy Channel...Association for Computational Linguistics
 
module5_backtrackingnbranchnbound_2022.pdf
module5_backtrackingnbranchnbound_2022.pdfmodule5_backtrackingnbranchnbound_2022.pdf
module5_backtrackingnbranchnbound_2022.pdfShiwani Gupta
 
[Paper Reading] Attention is All You Need
[Paper Reading] Attention is All You Need[Paper Reading] Attention is All You Need
[Paper Reading] Attention is All You NeedDaiki Tanaka
 
On the value of stochastic analysis for software engineering
On the value of stochastic analysis for software engineeringOn the value of stochastic analysis for software engineering
On the value of stochastic analysis for software engineeringCS, NcState
 
Cassandra deep-dive @ NoSQLNow!
Cassandra deep-dive @ NoSQLNow!Cassandra deep-dive @ NoSQLNow!
Cassandra deep-dive @ NoSQLNow!Acunu
 
super vector machines algorithms using deep
super vector machines algorithms using deepsuper vector machines algorithms using deep
super vector machines algorithms using deepKNaveenKumarECE
 
Online learning, Vowpal Wabbit and Hadoop
Online learning, Vowpal Wabbit and HadoopOnline learning, Vowpal Wabbit and Hadoop
Online learning, Vowpal Wabbit and HadoopHéloïse Nonne
 
PR243: Designing Network Design Spaces
PR243: Designing Network Design SpacesPR243: Designing Network Design Spaces
PR243: Designing Network Design SpacesJinwon Lee
 
Realtime Per Face Texture Mapping (PTEX)
Realtime Per Face Texture Mapping (PTEX)Realtime Per Face Texture Mapping (PTEX)
Realtime Per Face Texture Mapping (PTEX)basisspace
 
PR-183: MixNet: Mixed Depthwise Convolutional Kernels
PR-183: MixNet: Mixed Depthwise Convolutional KernelsPR-183: MixNet: Mixed Depthwise Convolutional Kernels
PR-183: MixNet: Mixed Depthwise Convolutional KernelsJinwon Lee
 
Understanding Basics of Machine Learning
Understanding Basics of Machine LearningUnderstanding Basics of Machine Learning
Understanding Basics of Machine LearningPranav Ainavolu
 
Algebra 2 Lesson 3-9
Algebra 2 Lesson 3-9Algebra 2 Lesson 3-9
Algebra 2 Lesson 3-9Kate Nowak
 
Artificial Intelligence, Machine Learning and Deep Learning
Artificial Intelligence, Machine Learning and Deep LearningArtificial Intelligence, Machine Learning and Deep Learning
Artificial Intelligence, Machine Learning and Deep LearningSujit Pal
 
Puzzle-Based Automatic Testing: Bringing Humans Into the Loop by Solving Puzz...
Puzzle-Based Automatic Testing: Bringing Humans Into the Loop by Solving Puzz...Puzzle-Based Automatic Testing: Bringing Humans Into the Loop by Solving Puzz...
Puzzle-Based Automatic Testing: Bringing Humans Into the Loop by Solving Puzz...Sung Kim
 
Document Analysis with Deep Learning
Document Analysis with Deep LearningDocument Analysis with Deep Learning
Document Analysis with Deep Learningaiaioo
 
"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)
"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)
"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)Tech in Asia ID
 
20190927 generative models_aia
20190927 generative models_aia20190927 generative models_aia
20190927 generative models_aiaYi-Fan Liou
 
LINEAR PROGRAMMING
LINEAR PROGRAMMINGLINEAR PROGRAMMING
LINEAR PROGRAMMINGrashi9
 
Deep learning with Keras
Deep learning with KerasDeep learning with Keras
Deep learning with KerasQuantUniversity
 

Ähnlich wie backtracking algorithms of ada (20)

Knapsack problem using fixed tuple
Knapsack problem using fixed tupleKnapsack problem using fixed tuple
Knapsack problem using fixed tuple
 
Chris Dyer - 2017 - Neural MT Workshop Invited Talk: The Neural Noisy Channel...
Chris Dyer - 2017 - Neural MT Workshop Invited Talk: The Neural Noisy Channel...Chris Dyer - 2017 - Neural MT Workshop Invited Talk: The Neural Noisy Channel...
Chris Dyer - 2017 - Neural MT Workshop Invited Talk: The Neural Noisy Channel...
 
module5_backtrackingnbranchnbound_2022.pdf
module5_backtrackingnbranchnbound_2022.pdfmodule5_backtrackingnbranchnbound_2022.pdf
module5_backtrackingnbranchnbound_2022.pdf
 
[Paper Reading] Attention is All You Need
[Paper Reading] Attention is All You Need[Paper Reading] Attention is All You Need
[Paper Reading] Attention is All You Need
 
On the value of stochastic analysis for software engineering
On the value of stochastic analysis for software engineeringOn the value of stochastic analysis for software engineering
On the value of stochastic analysis for software engineering
 
Cassandra deep-dive @ NoSQLNow!
Cassandra deep-dive @ NoSQLNow!Cassandra deep-dive @ NoSQLNow!
Cassandra deep-dive @ NoSQLNow!
 
super vector machines algorithms using deep
super vector machines algorithms using deepsuper vector machines algorithms using deep
super vector machines algorithms using deep
 
Online learning, Vowpal Wabbit and Hadoop
Online learning, Vowpal Wabbit and HadoopOnline learning, Vowpal Wabbit and Hadoop
Online learning, Vowpal Wabbit and Hadoop
 
PR243: Designing Network Design Spaces
PR243: Designing Network Design SpacesPR243: Designing Network Design Spaces
PR243: Designing Network Design Spaces
 
Realtime Per Face Texture Mapping (PTEX)
Realtime Per Face Texture Mapping (PTEX)Realtime Per Face Texture Mapping (PTEX)
Realtime Per Face Texture Mapping (PTEX)
 
PR-183: MixNet: Mixed Depthwise Convolutional Kernels
PR-183: MixNet: Mixed Depthwise Convolutional KernelsPR-183: MixNet: Mixed Depthwise Convolutional Kernels
PR-183: MixNet: Mixed Depthwise Convolutional Kernels
 
Understanding Basics of Machine Learning
Understanding Basics of Machine LearningUnderstanding Basics of Machine Learning
Understanding Basics of Machine Learning
 
Algebra 2 Lesson 3-9
Algebra 2 Lesson 3-9Algebra 2 Lesson 3-9
Algebra 2 Lesson 3-9
 
Artificial Intelligence, Machine Learning and Deep Learning
Artificial Intelligence, Machine Learning and Deep LearningArtificial Intelligence, Machine Learning and Deep Learning
Artificial Intelligence, Machine Learning and Deep Learning
 
Puzzle-Based Automatic Testing: Bringing Humans Into the Loop by Solving Puzz...
Puzzle-Based Automatic Testing: Bringing Humans Into the Loop by Solving Puzz...Puzzle-Based Automatic Testing: Bringing Humans Into the Loop by Solving Puzz...
Puzzle-Based Automatic Testing: Bringing Humans Into the Loop by Solving Puzz...
 
Document Analysis with Deep Learning
Document Analysis with Deep LearningDocument Analysis with Deep Learning
Document Analysis with Deep Learning
 
"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)
"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)
"Practical Machine Learning With Ruby" by Iqbal Farabi (ID Ruby Community)
 
20190927 generative models_aia
20190927 generative models_aia20190927 generative models_aia
20190927 generative models_aia
 
LINEAR PROGRAMMING
LINEAR PROGRAMMINGLINEAR PROGRAMMING
LINEAR PROGRAMMING
 
Deep learning with Keras
Deep learning with KerasDeep learning with Keras
Deep learning with Keras
 

Kürzlich hochgeladen

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 

Kürzlich hochgeladen (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 

backtracking algorithms of ada

  • 1. 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 backtrack method, the solution must be expressible as an n-tuple(x1,…,xn), where the xi are chosen from some finite set si • The solution vector must satisfy the criterion function P(x1 , ….. , xn). 1 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 2. BACKTRACKING (Contd..) • Suppose there are m n-tuples which are possible candidates for satisfying the function P. • Then m= m1, m2…..mn where mi is size of set si 1<=i<=n. • The brute force approach would be to form all of these n-tuples and evaluate each one with P, saving the optimum. 2 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 3. BACKTRACKING (Contd..) • The backtracking algorithm has the ability to yield the same answer with far fewer than m-trials. • In backtracking, the solution is built one component at a time. • Modified criterion functions Pi (x1...xn) called bounding functions are used to test whether the partial vector (x1,x2,......,xi) can lead to an optimal solution. • If (x1,...xi) is not leading to a solution, mi+1,....,mn possible test vectors may be ignored. 3 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 4. BACKTRACKING (Contd..) • The constraints may be of two categories. • EXPLICIT CONSTRAINTS are rules which restrict the values of xi. Examples xi  0 or x1= 0 or 1 or li  xi  ui. • All tuples that satisfy the explicit constraints define a possible solution space for I. • IMPLICIT CONSTRAINTS describe the way in which the xi must relate to each other . • Implicit constraints allow to find those tuples in the solution space that satisfy the criterion function. 4 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 5. Example : 8 queens problem • The problem is to place eight queens on an 8 x 8 chess board so that no two queens attack i.e. no two of them are on the same row, column or diagonal. • Strategy : The rows and columns are numbered through 1 to 8. • The queens are also numbered through 1 to 8. • Since each queen is to be on a different row without loss of generality, we assume queen i is to be placed on row i . 5 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 6. 8 queens problem (Contd..) • The solution is an 8 tuple (x1,x2,.....,x8) where xi is the column on which queen i is placed. • The explicit constraints are : Si = {1,2,3,4,5,6,7,8} 1  i  n or 1  xi  8 i = 1,.........8 • The solution space consists of 88 8- tuples. 6 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 7. 8 queens problem (Contd..) The implicit constraints are : (i) no two xis can be the same that is, all queens must be on different columns. (ii) no two queens can be on the same diagonal. (i) reduces the size of solution space from 88 to 8! 8 – tuples. Two solutions are (4,6,8,2,7,1,3,5) and (3,8,4,7,1,6,2,5) 7 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 8. 8 queens problem (Contd..) 1 2 3 4 5 6 7 8 1 Q 2 Q 3 Q 4 Q 5 Q 6 Q 7 Q 8 Q 8 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 9. State space tree representation Solution Space : • Tuples that satisfy the explicit constraints define a solution space. • The solution space can be organized into a tree. • Each node in the tree defines a problem state. • All paths from the root to other nodes define the state- space of the problem. • Solution states are those states leading to a tuple in the solution space. • Answer nodes are those solution states leading to an answer-tuple( i.e. tuples which satisfy implicit constraints). 9 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 10. State space tree representation contd.. • The problem may be solved by systematically generating the problem states determining which are solution states, and determining the answer states. • Let us see the following terminology • LIVE NODE A node which has been generated and all of whose children are not yet been generated . • E-NODE (Node being expanded) - The live node whose children are currently being generated . 10 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 11. State space tree representation contd.. • DEAD NODE - A node that is either not to be expanded further, or for which all of its children have been generated. • DEPTH FIRST NODE GENERATION- In this, as soon as a new child C of the current E-node R is generated, C will become the new E-node. R will become E-node again when C has been fully explored. 11 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 12. State space tree representation contd.. • BOUNDING FUNCTION - will be used to kill live nodes without generating all their children. • BACTRACKING-is depth – first node generation with bounding functions. • BRANCH-and-BOUND is a method in which E-node remains E-node until it is dead. 12 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 13. State space tree representation contd.. • BREADTH-FIRST-SEARCH : Branch-and Bound with each new node placed in a queue . The front of the queen becomes the new E- node. • DEPTH-SEARCH (D-Search) : New nodes are placed in to a stack. The last node added is the first to be explored. 13 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 14. Example : 4 Queens problem 1 1 1 1 . . 2 2 2 3 . . . . 1 1 2 3 . . 4 14 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 15. State space tree: 4 Queens problem 1 x1 = 1 x1=2 2 18 x2=2 3 4 x2=1 x2=3 x2 = 4 B 3 8 13 19 24 29 x3=3 x3=4 2 3 B B 4 6 14 16 x3 = 1 x4=4 3 B 30 5 7 15 x4 = 3 B 31 15 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 16. State space tree: 4 Queens problem contd.. • If (x1….xi) is the path to the current E-node , a bounding function has the criterion that (x1..xi+1) represents a chessboard configuration, in which no queens are attacking. • A node that gets killed as a result of the bounding function has a B under it. 16 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 17. State space tree: 4 Queens problem contd.. • We start with root node as the only live node. The path is ( ); we generate a child node 2. • The path is (1).This corresponds to placing queen 1 on column 1 . • Node 2 becomes the E node. Node 3 is generated and immediately killed. (because x1=1,x2=2). • As node 3 is killed, nodes 4,5,6,7 need not be generated. 17 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 18. State space tree: 4 Queens problem contd.. • Node 8 is generated, and the path is (1,3). • Node 8 gets killed as all its children represent board configurations that cannot lead to answer. We backtrack to node 2 and generate another child node 13. • But the path (1,4) cannot lead to answer nodes. • So , we backtrack to 1 and generate the path (2) with node 18. We observe that the path to answer node is (2 4 1 3 ) • Other solution is (3, 1, 4, 2) 18 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 19. GENERAL BACKTRACKING METHOD • All answer nodes are to be found • If (x1…..xi) is a path from root to a node then T (x1,….,xi) be the set of all possible values for Xi+1, such that (x1,x2,…….,xi,xi+1) is also a path from root to a problem state. • B(x1…xi+1) or Bxi+1is false for the path (x1,..,xi+1) if the path cannot reach an answer node. • The solution vectors X (1: n) are those values which are generated by T and satisfy Bi+1. 19 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 20. GENERAL BACKTRACKING METHOD (Contd..) Procedure backtrack (n) // solution vectors are X(1:n)// // and printed as soon as generated // // T {X(1),….X(k-1)} gives all possible values of X(k) // given that X(1),…..,X(k-1) have already been chosen // // The predicates Bk (X(1),….X(k) ) determine those elements // // which satisfy the implicit constraints // // Implicit constraints are “no two X is can be the same” // Integer k, n; local X (1:n) 20 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 21. GENERAL BACKTRACKING METHOD (Contd..) K 1 while K <> 0 do if there remained an untried X(k) such that X(k)  T ( X (1) , …..X(k-1) ) and Bk (X (1) ,…,X(k) ) = true then if (X (1),…, X(k) ) is a path to an answer node then print ( X (1) ,…X (k) ) // and proceed for another// //solution with untried value of X(k)// K K+1 // consider next set// endif // end of if there remained ….// else K K-1 // backtrack to previous component as no value of X(k) //satisfies the constraints// endif repeat end Backtrack 21 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 22. EXAMPLE OF ALGORITHM WITH 4 QUEENS PROBLEMS k 1 loop 1 X0 =1,1 {1,2,3,4} and B1 (X (1)) = true 1 is not a path to answer node K  1+1=2 repeat K 2 loop 2 X(2){2,3,4}and B2 (1,2) is False but there remains untried X(k)=3 and X(K) =4 22 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 23. EXAMPLE OF ALGORITHM WITH 4 QUEENS PROBLEMS (Contd..) B2 (1,3)=true , but (1,3) Is not a path to answer node ; so K K+1=3 There is no X(3) such that B3(1,3,2) or B3 (1,3,4) is true . So backtrack K K-1=2 consider X (2)  4 23 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 24. EXAMPLE OF ALGORITHM WITH 4 QUEENS PROBLEMS (Contd..) (1,4) is not a path to answer (1,4,2) is not a path to answer B4(1,4,2,3)=false. Thus X(2)=4 is false With X(1)=1, we have seen that there is no X(2) satisfying the constraints so KK-1=2-1=1 There remained untried X(k)=2,3,4. Repeating with X(1)=2, we observe (2,4,1, 3) is a path to an answer node . Similarly the other solution is (3,1,4,2) 24 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 25. BACKTRACKING ALGORITHM WITH RECURSION Procedure RBACKTRACK (k) // on entering the first K-1 values X(1),…..,X(k-1)// // of the solution vector X(1:n) have been assigned // global n , X(1:n) for each X(k) such that X(k)  T ( X (1),..X(k-1) ) Do if Bk (X(1)..,X(k-1), X(k) )= true then { if ( X (1) ,….,X(k) ) is a path to an answer node then print ( X(1),……,X(k) ) endif if (k<n) CALL RBACKTRACK (k+1) endif }// end of if Bk (X(1)…// repeat // end of for each X(k)…// end RBACKTRACK 25 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 26. BACKTRACKING ALGORITHM WITH RECURSION (Contd..) EXAMPLE (RB – RBACKTRACK) Initially RB(1) is called for each X(1)  X(1) {1,2,3,4} and B1 (1) is true , but 1 is not an answer node. RB (2) is called X(2) {2,3,4} and B2 (1,3) = true and B2 (1,4) = true (1,3) is not an answer node , RB(3) is called,X(3) = 2, 26 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 27. BACKTRACKING ALGORITHM WITH RECURSION (Contd..) but (1,3,2) is not Answer node , so , RB(4) is called B4 (1,3,2,4) = false. (1,3,4,2) is not bounded so , X(2) = 4 is tried (1,4,2,3) is not bounded . With X(1)=1 no solution Now for X(1) = 2,3,4 repeat (2,4,1,3) is an answer node, other paths with X(1) = 2 are not leading to answer node. With X (1) = 3 , (3,1,4,2) is an answer node. X (1) = 4 - no solution. 27 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 28. EFFICIENCY OF BACKTRACKING (BT) ALGORITHM • The time required by a backtracking algorithm or the efficiency depends on four factors (i) The time to generate the next X(k); (ii) The number of X(k) satisfying the explicit constraints (iii) The time for bounding functions Bi (iv) The number of X(k) satisfying the Bi for all i. 28 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 29. EFFICIENCY OF BACKTRACKING ALGORITHM (Contd..) • The first three are relatively independent of the problem instance being solved. • The complexity for the first three is of polynomial complexity . • If the number of nodes generated is 2n , then the worst case complexity for a backtracking algorithm is O(P(n)2n) where P(n) is a polynomial in n . 29 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 30. Estimation Of Nodes generated in a BT Algorithm • Generate a random path in the state space tree. • Let X be a node at level i on this path. • Let mi be the children of X ( at level i+1 ) that do not get bounded. (i.e. mi are the nodes which can be considered for getting an answer node ). • Choose randomly one of the mi. • Continue this until this node is either is a leaf or all its children are bounded. 30 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 31. Estimation of Nodes generated in a BT Algorithm (Contd..) • Let m be the no. of unbounded nodes to be generated. • Let us assume that the bounding functions are static, i.e., the BT algorithm does not change its bounding functions. • The number of estimated number of unbounded nodes =1+m1+m1m2+….. +m1m2m3..mi where mi is the estimated no. of nodes at level i+ 1. 31 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 32. Estimation of Nodes generated in a BT Algorithm (Contd..) • The number of unbounded nodes on level one is 1. • The number of unbounded nodes on level 2 is m1 • The total no. of nodes generated till level 2 is 1 + m1  The total number of nodes generated till level i+1 is 1+m1+…+m1…mi . – The above procedure can be written as an algorithm. 32 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 33. Estimation of Nodes generated in a BTAlgorithm (Contd..) Procedure Estimate // This procedure follows a random path and estimates// // number of unbounded nodes // m1; r1; k1 loop Tk {X (k): X(k) T ( X(1) ,….X(k-1)) and Bk (X (1), …., X(k)) is TRUE} If size (Tk) = 0 then exit endif // SIZE returns the // r  r * SIZE (Tk) // size of the set Tk // m  m+r X (k)  CHOOSE (Tk) // CHOOSE makes a random choice of an element in Tk // k k+1 repeat return (m) end estimate 33 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)
  • 34. The n-queens problem and solution • In implementing the n – queens problem we imagine the chessboard as a two- dimensional array A (1 : n, 1 : n). • The condition to test whether two queens, at positions (i, j) and (k, l) are on the same row or column is simply to check i = k or j = l 34 Create PDF files without this message by purchasing novaPDF printer (http://www.novapdf.com)