Module 5 AOA
Module 5 AOA
Technique
• The algorithm explores branches of this tree, which represent the subsets
of the solution set. Before enumerating the candidate solutions of a
branch, the branch is checked against upper and lower estimated bounds
on the optimal solution and is discarded if it cannot produce a better
solution than the best one found so far by the algorithm.
Travelling Salesman Problem
using
Branch and Bound
https://www.youtube.com/watch?v=1FEP_sNb62k&t=672s
Traveling Salesman Problem using Branch And Bound
• Given a set of cities and distance between every pair of cities, the
problem is to find the shortest possible tour that visits every city
exactly once and returns to the starting point.
15 PUZZLE PROBLEM
USING BRANCH AND BOUND
• Each node X in the search tree is associated with a cost. The cost
function is useful for determining the next E-node. The next E-node is
the one with least cost. The cost function is defined as,
• C(X) = g(X) + h(X) where
• g(X) = cost of reaching the current node from the root
• h(X) = cost of reaching an answer node from X
Ideal Cost function for 15-puzzle Algorithm :
• We assume that moving one tile in any direction will have 1 unit cost.
Keeping that in mind, we define cost function for 15- puzzle algorithm
as below :
• c(x) = f(x) + h(x) where
• f(x) is the length of the path from root to x (the number of moves
so far)
• h(x) is the number of non-blank tiles not in their goal position (the
number of mis- - placed tiles). There are at least h(x) moves to
1 2 3 4
5 6 8
9 10 7 11
13 14 15 12
Initial arrangement
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15
Goal arrangement
1 2 3 4
5 6 8
9 10 7 11
13 14 15 12
left
up
right down
1 2 3 4 1 2 3 4 1 2 3 4
5 6 7 8 5 6 7 8 5 6 7 8
9 10 11 9 10 15 11 9 10 11
13 14 12 13 14 15 12
13 14 15 12
up down
C=3+2 C=3+0
1 2 3 4 1 2 3 4
5 6 7 5 6 7 8
9 10 11 8 9 10 11 12
13 14 15 12 13 14 15
Goal node
Pseudocode
Procedure15-PUZZLE
// live_node_set: set to hold the live nodes at any time
// lowcost: variable to hold the cost of the best cost at any given node
Begin
lowcost = ∞;
While live_node_set ≠∞ do
choose a branching node, k, such that k ∈ live_node_set; // k is a E-node
live_node_set= live_node_set - {k};
Generate the children of node k and the corresponding lower bounds;
Sk={(i, zi): i is child of k and zi its lower bound}
For each element (i, zi) in Sk do
if zi > U //more than lower bound??
Kill child i; // i is a child node
else
if child i is a solution
U = zi; current best = child i;
else
add child i to live_node_set;
endif;
endif;
endfor;
Endwhile;
End
Backtracking
Ms. Mrunali Desai
Backtracking Algorithms
https://www.codesdope.com/course/algorithms-backtracking/
N Queen Problem
• The N Queen is the problem of placing N chess
queens on an N×N chessboard so that no two
queens attack each other. For example,
following is a solution for 4 Queen problem.
The other solutions for 4 - queens The other solutions for 4 - queens
problems is (3, 1, 4, 2). problems is (2, 4, 1, 3).
Algorithm
Sum of Subsets
Subset sum
• Subset sum problem is to find subset of elements that are selected
from a given set whose sum adds up to a given number K.
Time Complexity:
= O(2^n)
Example
Output:
Graph coloring
M-coloring Problem