Module 2
Module 2
BRUTE FORCE
APPROACHES(conti…)
Exhaustive Search
• a brute-force approach to combinatorial problems.
• It suggests generating each and every element of the problem's
domain, selecting those of them that satisfy all the constraints, and
then finding a desired element.
• Examples for the Exhaustive Search
1.Traveling salesman problem
2. The knapsack problem
Traveling Salesman Problem (TSP)
Problem Statement: Find the shortest tour through a given set of n cities that
visits each city exactly once before returning to the city where it started.
• Modeled by a weighted graph, with the graph's vertices representing the
cities and the edge weights specifying the distances.
• The problem can be stated as the problem of finding the shortest Hamiltonian
circuit of the graph.
• A Hamiltonian circuit is defined as a cycle that passes through all the vertices
of the graph exactly once.
• A Hamiltonian circuit can also be defined as a sequence of 𝑛+1 adjacent
vertices 𝑣𝑖0,𝑣𝑖1,…,𝑣𝑖(𝑛−1),𝑣𝑖0 where the first vertex of the sequence is the
same as the last one, and all the other 𝑛−1 vertices are distinct.
Example problem
Knapsack Problem
• Given n items of known weights w1 , ... , Wn and values v1, ... , vn
and a knapsack of capacity W , find the most valuable subset of the
items that fit into the knapsack, such that the total weight does not
exceed 𝑊and the total value is maximized.
• The exhaustive-search approach to this problem leads to generating
all the subsets of the set of n items given, computing the total weight
of each subset to identify feasible subsets
Decrease-and-Conquer
• technique is based on exploiting the relationship between a solution
to a given instance of a problem and a solution to a smaller instance
of the same problem.
• Once such a relationship is established, it can be exploited either top
down (recursively) or bottom up (without a recursion).
• There are three major variations of decrease-and-conquer
1. Decrease by a constant
2. Decrease by a constant factor
3. Variable size Decrease
Decrease by CONSTANT(ONE)
• The size of an instance is reduced by the same constant on each
iteration of the algorithm. Typically, this constant is equal to one