0% found this document useful (0 votes)
16 views22 pages

AOA Module5 PPT

Uploaded by

jayantpatil9111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views22 pages

AOA Module5 PPT

Uploaded by

jayantpatil9111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

What is Backtracking?

⚫ Suppose you have to make a series of decisions,


among various choices, where
⚫ You don’t have enough information to know what to
choose
⚫ Each decision leads to a new set of choices
⚫ Some sequence of choices (possibly more than one)
may be a solution to your problem
⚫ Backtracking is a methodical way of trying out
various sequences of decisions, until you find one
that “works”
Contd ...
The solution is based on finding one or more vectors
that maximize, minimize, or satisfy a criterion function P(x1,
…. xn).
All possible solutions require a set of constraints,
divided into two categories:
•Explicit Constraint: Explicit constraints are rules that
restrict each xi to take on values only from a given set. Ex:
xn= 0 or 1.
• Implicit Constraint: Implicit Constraints are rules
that determine which of the tuple in the solutions space of I
satisfy the criterion function.
Basic
I. Terms
Solution Space: All tuples that satisfy the explicit constraints
define a possible solution space for a particular instance T of
the problem. Example:
A

B C

Fig:
Tree organization of a solution space
D E

II. Problem State: A problem state is the state that is defined by


all the nodes within the tree organization.
A
Example
:
Fig: Problem
State
B C
Contd ...
III. Solution States: These are the problem states S for which the
path form the root to S defines a tuple in the solution space.
⚫ square nodes (◻) Example A
:
indicate solution
B C
Fig: Solution
State

D
E F G

IV. State Space Tree: Is the set of paths from root node to other
nodes. State space tree is the tree organization of the
solution of the solution space.
V. Answer States: These solution states S, for which the path
from the root node to S defines a tuple that is a member of
the set of solutions (i.e., it satisfies the implicit constraints)
of the problem.
Eg: From above tree nodes D, F, and G are the Answer States.
Contd ...
VI. Live Node: A node which has been generated but whose
children have not yet been generated is live node.
VII. E-Node: The live nodes whose children are currently being
generated is called the E-node (node being expanded).
III. Dead Node: It is generated node, that is either not to be
expanded further or one for which all of its children has been
generated.
1
1

2 3
2 3

(a)
4
(b)
Fig: Dead nodes
Nodes 1,2,and 3
Nodes 1,3,and 4
N-queen problem
1) Start in the leftmost column
2) If all queens are placed return true
3) Try all rows in the current column.
Do following for every tried row.
a) If the queen can be placed safely in this row then mark
this [row, column] as part of the solution and recursively
check if placing queen here leads to a solution.
b) If placing queen in [row, column] leads to a solution then
return true.
c) If placing queen doesn't lead to a solution then umark
this [row, column] (Backtrack) and go to step (a) to try
other rows.
4) If all rows have been tried and nothing worked, return false
to trigger backtracking.
n-queen problem
4-queen problem tree portion
Algorithm
Algorithm

Time Complexity is O(n!) not the nn


Sum of subsets
Subset sum problem is to find subset of elements that
are selected from a given set whose sum adds up to a
given number ‘M’. We are considering the set contains
non-negative values. It is assumed that the input set is
unique.
Algorithm

Time Complexity is O(n.2n )


Ex:
Let n=6, m=30, and w[1:6] = { 5,10,12,13,15,18 }
Graph Coloring
M-Colorability optimization
Chromatic number
Planner Graph
Adjacency Matrix
Map and Planner Graph representation

1 2 3 4 5
1 0 1 1 1 0
2 1 0 1 1 1
3 1 1 0 1 0
4 1 1 1 0 1
5 0 1 0 1 0
Algorithm
Time Complexity is O(n.mn )
Ex:
n=4, m=3
Hamilton Cycles
A Hamiltonian cycle, also called a Hamiltonian circuit,
Hamilton cycle, or Hamilton circuit, is a graph cycle (i.e.,
closed loop) through a graph that visits each node exactly once
Algorithms
Time Complexity is O(n!

You might also like