Mdule 2 Lecture 6
Mdule 2 Lecture 6
LECTURE-6
GREEDY SEARCH ALGRORITHM
The greedy method is one of the strategies like Divide and conquer used to solve the
problems. This method is used for solving optimization problems. An optimization
problem is a problem that demands either maximum or minimum results. Let's
understand
The through
Greedy some terms.
method is the simplest and straightforward approach. It is not an
algorithm, but it is a technique. The main function of this approach is that the
decision is taken on the basis of the currently available information. Whatever the
current information is present, the decision is made without worrying about the
effect of the current decision in future.
This technique is basically used to determine the feasible solution that may
or may not be optimal.
The feasible solution is a subset that satisfies the given criteria. The optimal solution
is the solution which is the best and the most favorable solution in the subset
Components of Greedy Algorithm
Greedy algorithm makes decisions based on the information available at each phase
without considering the broader problem. So, there might be a possibility that the
greedy solution does not give the best solution for every problem.
It follows the local optimum choice at each stage with a intend of finding the global
optimum. Let's understand through an example.
The problem is that we have to travel this journey from A to B. There are various solutions
to go from A to B. We can go from A to B by walk, car, bike, train, aeroplane, etc.
There is a constraint in the journey that we have to travel this journey within 12 hrs. If I
go by train or aeroplane then only, I can cover this distance within 12 hrs. There are
many solutions to this problem but there are only two solutions that satisfy the constraint.
If we say that we have to cover the journey at the minimum cost. This means that we
have to travel this distance as minimum as possible, so this problem is known as a
minimization problem. Till now, we have two feasible solutions, i.e., one by train and
another one by air. Since travelling by train will lead to the minimum cost so it is an
optimal solution
SOLVING THE EXAMPLES OF GREEDY SEARCH
ALGORITHM
Evaluation Function
The evaluation function, f(x), for the greedy best-first search algorithm is
the following:
f(x) = h(x)
The Algorithm
1.Initialize a tree with the root node being the start node in the open list.
2.If the open list is empty, return a failure, otherwise, add the current node to the closed
list.
3.Remove the node with the lowest h(x) value from the open list for exploration.
4.If a child node is the target, return a success. Otherwise, if the node has not been in
either the open or closed list, add it to the open list for exploration.
Example