Case 1 (full g(n), a.k.a. blind search):
If you use an evaluation function f(n)
to choose the next path to be explored based only on g(n)
, you are basically using a Dijkstra's algorithm. In other words, if f(n) = g(n) + h(n)
and h(n) = 0
, f(n) = g(n)
and you are exploring in each iteration the path with minimum cost. This guarantees to find the optimal path (with only positive costs in the graph) but you may explore suboptimal paths.
For example, in the following graph we want to find the path from s
to t
:
n1 node | h(node)
/ \ s | 3
2 / \ 1 n1 | 1
/ \ n2 | 4
s t
\ /
1 \ / 4
\ /
n2
and the table gives us the heuristic evaluation for each node (let me suppose we have a perfect heuristic, i.e. the heuristic value always corresponds to the shortest path to the goal). Thus, in the first iteration s is expanded and n1
and n2
added to the OPEN list.
When a blind search is performed (or full g(n)
), then:
f(n1) = g(n1) = 2
.
f(n2) = g(n2) = 1
.
and node n2
will be explored, since it has the minimum g-value in the OPEN list.
However, when we use A* and the heuristic values:
n1
will be explored and t
afterwards, leading to the optimal solution and not exploring the suboptimal path by n2
along the way.
Therefore, full g(n)
means Dijkstra vs A*. If your heuristic is a good estimation (let's simplify like this), A* will always be preferable.
Case 2 (full h(n)):
We have a different case here, since we are not using the cost of the path already found, we are only trusting the heuristic evaluation of our function. Depending on the quality of the heuristic you can end up exploring all nodes in the graph or only the optimal path, but you have lost the beautiful theoretical properties of A*.