0% found this document useful (0 votes)
0 views

Mdule 2 Lecture 6

The document discusses the greedy search algorithm, a technique used for solving optimization problems by making decisions based on currently available information without considering future consequences. It outlines the components of the greedy algorithm, its applications, advantages, and disadvantages, and provides examples to illustrate its functionality. Additionally, it explains the evaluation function for greedy best-first search and highlights potential issues with this approach.

Uploaded by

Balamurali Gunji
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Mdule 2 Lecture 6

The document discusses the greedy search algorithm, a technique used for solving optimization problems by making decisions based on currently available information without considering future consequences. It outlines the components of the greedy algorithm, its applications, advantages, and disadvantages, and provides examples to illustrate its functionality. Additionally, it explains the evaluation function for greedy best-first search and highlights potential issues with this approach.

Uploaded by

Balamurali Gunji
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

MODULE-2

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

The components that can be used in the greedy algorithm are:


•Candidate set: A solution that is created from the set is known as a candidate set.
•Selection function: This function is used to choose the candidate or subset which
can be added in the solution.
•Feasibility function: A function that is used to determine whether the candidate or
subset can be used to contribute to the solution or not.
•Objective function: A function is used to assign the value to the solution or the
partial solution.
•Solution function: This function is used to intimate whether the complete function
has been reached or not.
SLOVE THE GRAPH USING GREEDY SEARCH
ALGORITHM
For example, suppose we want to find the longest path in the graph below from
root to leaf. Let's use the greedy algorithm here.
Greedy Approach

1. Let's start with the root node 20. The weight of


the right child is 3 and the weight of the left
child is 2.

2. Our problem is to find the largest path. And, the


optimal solution at the moment is 3. So, the
greedy algorithm will choose 3.

3. Finally the weight of an only child of 3 is 1. This


gives us our final result 20 + 3 + 1 = 24.

However, it is not the optimal solution. There is


another path that carries more weight (20 + 2 +
10 = 32) as shown in the image below.
Applications of Greedy Algorithm
•It is used in finding the shortest path.
•It is used to find the minimum spanning tree using the prim's algorithm or the
Kruskal's algorithm.
•It is used in a job sequencing with a deadline.
•This algorithm is also used to solve the fractional knapsack problem.
Disadvantages of using 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.

Advantages of Greedy Approach


•The algorithm is easier to describe.
•This algorithm can perform better than other algorithms (but, not in all cases).
Let's understand through an example.

Suppose there is a problem 'P'. I want to travel from A to B shown as


below:
P:A→B

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)

Here, the evaluation function is equal to the heuristic function. Since


this search disregards edge weights, finding the lowest-cost path is
not guaranteed.

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

In this example, the cost is measured strictly using


the heuristic value. In other words, how close it is
to the target.
C has the lowest cost of 6. Therefore, the search
will continue like so:

The total cost for the path (P -> C -> U -> S)


evaluates to 11. The potential problem with a
greedy best-first search is revealed by the
U has the lowest cost compared to M and R, so the path (P -> R -> E -> S) having a cost of 10,
search will continue by exploring U. Finally, S has a which is lower than (P -> C -> U -> S).
heuristic value of 0 since that is the target node: Greedy best-first search ignored this path
because it does not consider the edge
weights.
So now the goal node G has been reached and the
path we will follow is A->C->F->G
EXAMPLES TO SOLVE
THANK YOU

You might also like