Cse 408 Assignment
Cse 408 Assignment
This is a simple algorithm, but it demonstrates that sometimes you need to return
to a previous state and re-evaluate a previous decision in order to solve a
problem.
BACKTRACKING is a general algorithmic technique that considers searching every
possible combination in order to solve an optimization problem. Backtracking
uses depth-first-search approach. By inserting more knowledge of the problem,
the search tree can be pruned to avoid considering cases that don’t look
promising. While backtracking is useful for hard problems to which we do not
know more efficient solutions, it is a poor solution for the everyday problems that
other techniques are much better at solving.
complexity
- worst case time complexity: Ɵ(2^n)
- space complexity: Ɵ(1)
example….
Write an algorithm of sum of subsets. Solve following problem and draw portion of state space tree M =
35, W = (5, 7, 10, 12, 15, 18, 20)
Problem statement:
Let, S=S1….S−n
be a set of n positive integers, then we have to find a subset whose sum is equal to given positive
integer d.It is always convenient to sort the set’s elements in ascending order. That is,
S1≤S2≤….≤Sn
Algorithm:
Example:
Solve following problem and draw portion of state space tree M = 35, W = (5, 7, 10, 12, 15, 18,
20)
(roll no- k18ms 11816118)
2. .ASSIGNMENT PROBLEM (using BRANCH AND BOUND
ALGORITHM)
● Assignment problem refers to special class of linear programming
problems that involves determining the most efficient assignment of
people to projects,salespeople to territories, contracts to bidders and so
on.
● It is often used to minimize total cost or time of performing task.
● One important characteristic of assignment problems is that only one job
is assigned to one machine(or project)
● Each Assignment problem has a Matrix associated with it.
● The number in the table indicated COST associated with the assignment
● The most efficient linear programming algorithm to find optimum
solution to an assignment problem is Branch and Bound method.
9 2 1 8
6 4 3 7
5 8 1 8
7 6 9 4
a
b
c
d
ALGORITHM
/* find min cost uses least() and Add() to maintain the list of live nodes */
/*least() finds a live node with least cost, deletes it from the list and return it */
/*Add(x) calculates the cost of x and adds it to the list of live nodes */
/*Implements list of live nodes as a min heap*/
3. KNAPSACK PROBLEM
(using DYNAMIC PROGRAMMING )
EXAMPLE
KNAPSACK ALGORITHM
for w = 0 to W
B[0,w] = 0
for i = 1 to n
B[i,0] = 0
for i = 1 to n
for w = 0 to W
if wi<= w // item i can be part of the solution
if bi+ B[i-1,w-wi] > B[i-1,w]
B[i,w] = bi+ B[i-1,w- wi]
else
B[i,w] = B[i-1,w]
else B[i,w] = B[i-1,w] // wi> w