Currently, I am a new to the Artificial Intelligence. I have a problem with the greedy search algorithm. I saw one question in a tutorial but can't understand how to answer it. Please help me. Any help much appreciated.
Consider the given figure 1. The values in each node represent the heuristic cost from that node to goal node (G) and the values within the arcs represent the path cost between two nodes.
- If B is the starting node and G is the goal node,
- Find the traversal using Greedy Search Algorithm.
- Find the traversal using A* Search Algorithm
I assume that the greedy search algorithm that you refer to is having the greedy selection strategy as follows: Select the next node which is adjacent to the current node and has the least cost/distance from the current node. Note that the greedy solution don't use heuristic costs at all.
Consider the following figure well crafted such that it proves that greedy solution is not optimal.
The path highlighted with red shows the path taken by Greedy Algorithm and the path highlighted with green shows the path taken by Heuristic A* algorithm.
Explanation:
Greedy algorithm
Cost for the path by Greedy Algorithm (highlighted in red): B -> E -> F -> H -> G
= 5+6+6+3
= 20
A* algorithm (before going forward have a look at the wiki page for A* algorithm and understand what g(n)
and h(n)
are if you haven't already understood this concept):
f(n) = g(n) + h(n)
. Here g(n) is the immediate cost on the arc and h(n)
is the heuristic value on the node
f(n)
. So we move to node B.B -> C -> D -> H -> G
and it's cost is 6+6+4+3
= 19
By the above example we can see that the cost of heuristic path is less than greedy algorithm. Hence greedy algorithm is not always optimal.