Professional Documents
Culture Documents
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15
Heuristic algorithms
A heuristic is a technique designed for solving a problem
more quickly when classic methods are too slow, or for
finding an approximate solution when classic methods fail to
find any exact solution.
This is achieved by trading optimality, completeness,
accuracy, or precision for speed. In a way, it can be
considered a shortcut. The objective of a heuristic is to
produce a solution in a reasonable time frame that is good
enough for solving the problem at hand. This solution may
not be the best of all the actual solutions to this problem, or it
may simply approximate the exact solution. But it is still
valuable because finding it does not require a prohibitively
long time.
Heuristic algorithms
Heuristics may produce results by themselves, or they may be
used in conjunction with optimization algorithms to improve
their efficiency.
Results about NP-hardness in theoretical computer science
make heuristics the only viable option for a variety of complex
optimization problems that need to be routinely solved in real-
world applications.
Trade-off
The trade-off criteria for deciding whether to use a heuristic
for solving a given problem include the following:
Optimality: When several solutions exist for a given problem,
the heuristic has to guarantee that the near best solution can be
found. In some applications only best solution is acceptable
and a heuristic algorithm may not guarantee that.
Heuristics cont....(Trade off)
Completeness: When several solutions exist for a given
problem(8 queens), can the heuristic find them all if
required? Many heuristics are only meant to find one
solution.
Accuracy and precision: Can the heuristic provide a
confidence interval for the purported solution? Is the error
bar on the solution unreasonably large?
Execution time: There can be many heuristics and some are
faster than others(16-puzzle). Some heuristics are only
marginally quicker than classic methods.
In some cases, it may be difficult to decide whether the
solution found by the heuristic is good enough, because the
theory underlying that heuristic is not very elaborate.
Heuristics cont....
The heuristic approach to problem solving consists of applying
human intelligence, experience, common sense and certain rules of
thumb (or heuristics) to develop an acceptable, but not necessarily
an optimum, solution to a problem. Of course, determining what
constitutes an acceptable solution is part of the task of deciding
which approach to use.
Often the effort (manpower, computer, and other resources)
required, the time limits on when the solution is needed, and the
cost to compile, process, and analyze all the data required for
deterministic or other complicated procedures preclude their
usefulness or favour the faster, simpler heuristic approach. Thus,
the heuristic approach is generally used when deterministic
techniques or are not available, economical, or practical.
Traveling Salesman problem
Given a complete graph with nonnegative edge costs, find
a minimum cost cycle visiting every vertex exactly once.
Application : Given a number of cities and the costs of
traveling from any city to any other city, what is the
cheapest round-trip route that visits each city exactly once
and then returns to the starting city.
Travelling salesman problem
Approx-
Approx-TSP-Tour(G,c)
TSP-Tour(G,c)
11 select vertexrrv[G]
selectaavertex v[G]to tobe
beaa“root”
“root”vertex;
vertex;
22 call
callMST-Prim(G,c,r)
MST-Prim(G,c,r)to toconstruct
constructMST
MSTwith
withroot
rootr;r;
33 let
letLL==vertices
verticeson
onpreorder
preordertree
treewalk
walkofofMST;
MST;
44 let
letHH==cycle
cyclethat
thatvisits
visitsvertices
verticesin
inthe
theorder
orderL;
L;
return
returnHH
Cheapest Link Algorithm
The cheapest link algorithm is a greedy heuristic algorithm
for finding candidate solutions to the travelling salesman
problem. The cheapest link algorithm begins by choosing
the route that is the shortest distance between any two
cities. It continues by choosing the next shortest link
between any two cities. After the first two links, you must
make certain that no link closes the loop until all of the
cities are connected and also not more than two edges
emanate from a vertex. This method can at times find the
best overall solution, but it is not guaranteed to.
Cheapest Link Algorithm
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15
Randomized algorithms
We define a randomized algorithm as an algorithm
that uses random numbers at least once during the
computation to make a decision. A randomized
algorithm is an algorithm whose working not only
depends on the input but also on certain random
choices made by the algorithm.
Example: In Quicksort, using a random number to choose a
pivot
Example: Real world simulations :Car parking simulation,
scheduling algorithms simulation, flight reservation
simulation, Playing cards simulation
Quick Sort
Select: pick an arbitrary
element x in S to be the pivot.
14
Randomized Algorithms
INPUT ALGORITHM
OUTPUT
RANDOM NUMBERS
89
89
89
Las Vegas Algorithms
Las Vegas Algorithms: These refer to the randomized
algorithms that always come up with a/the correct
answer. Their expected running time is polynomial in the
size of their input.
In the worst case, however, a Las Vegas algorithm may
take exponentially long. One example of a Las Vegas
algorithm is Quicksort : it makes some of its decisions
based on random numbers, it always produces the correct
result, and its expected running and worst-case running
times are n log n and n2 , respectively.
Monte Carlo Algorithms
Monte Carlo Algorithms: These refer to the randomized
algorithms that sometimes come up with an incorrect answer.
Like Las Vegas algorithms their expected running time is
polynomial but may be exponential.
By performing independent runs of a Monte Carlo algorithm,
we can decrease the chances of obtaining an incorrect result to
a value as small as we like. For example, if a particular Monte
Carlo algorithm produces an incorrect result with probability
1/4, and we have the ability to detect an incorrect result, then
the probability of not obtaining a correct answer after t
independent runs is (1/4)t.
In some contexts, such as in optimization problems, we do not
have the ability to detect an incorrect answer, but can compare
different answers and pick the best one.