I'm learning about graph search and tree search recently and I see many examples mention something like "the path returned by xxx graph search is..." However, graph search is a traversal method, how can it return a path?
We know in tree search, each node corresponds to a particular path and by visiting a node, we know the corresponding path. I'm familiar with tree search enough, but, in graph search, the intention is to visit the destination, rather than find a path to the destination. Then, how can we define a path returned by graph search?
For example, below is a graph.
Graph
B
/ \
/ \
Start Destination
\ /
\ /
C
When we do BFS on start, the visiting sequence is Start-B-C-Destination
or Start-C-B-Destination
. Then, what should be the returned path? If we are using a queue, we can say we enqueue Destination
when visiting B
(or C
) so the returned path is Start-B-Destination
(or Start-C-Destination
), then what about the following graph?
Graph
B
/ \
/ \
Start-----D-----Destination
\ /
\ /
C
Clearly, D
is enqueued when visiting Start
, so the only possible path should be Start-D-Destination
?
There are more problems in A* search. If a node is visited not from the shortest path (due to poor heuristic function), then what should be the final returned path? For example, in the below graph, the visiting sequence is Start-B-D-C-Destination
, then what should be the returned path? Start-B-D-Destination
or Start-C-D-Destination
? We visited D
when B
is in the fringe, however, when we calculate the cost from Start
to D
, we are calculating Start-C-D
and the cost should be 2 rather than 3.
Graph
B
/ \
1 2
/ \
Start D--5--Destination
\ /
1 1
\ /
C
h(B) = 2, h(C) = 4, h(D) = 1
I think all these problems are caused by the intention of graph search isn’t to find a path and graph search will lead to ambiguity when selecting which node should be included in the final path.
Thanks for you patience and I’ll appreciate it a lot if anyone can give me an answer.