Input: source = 0, target = 9
edgeList = [ [ 0, 1, 3 ], [ 0, 2, 6 ], [ 0, 3, 5 ], [ 1, 4, 9 ],
[ 1, 5, 8 ], [ 2, 6, 12 ], [ 2, 7, 14 ], [ 3, 8, 7 ],
[ 8, 9, 5 ], [ 8, 10, 6 ], [ 9, 11, 1 ], [ 9, 12, 10 ], [ 9, 13, 2 ] ]
Output: 0 1 3 2 8 9
Explanation: Following describes the working of best first search:
- Start at node 0. Among its neighbors, node 1 has the lowest cost (edge cost 3), so move from 0 to 1.
- From node 1, since a better path forward isn’t available, backtrack to node 0.
- From node 0, choose the next best neighbor—node 3 (edge cost 5)—and move to node 3.
- At node 3, find that moving to node 2 leads to a lower incremental cost.
- Then proceed from node 2 to node 8, and finally from node 8 to node 9 (the target).
Input: source = 0, target = 8
edgeList = [ [ 0, 1, 3 ], [ 0, 2, 6 ], [ 0, 3, 5 ], [ 1, 4, 9 ],
[ 1, 5, 8 ], [ 2, 6, 12 ], [ 2, 7, 14 ], [ 3, 8, 7 ],
[ 8, 9, 5 ], [ 8, 10, 6 ], [ 9, 11, 1 ], [ 9, 12, 10 ], [ 9, 13, 2 ] ]
Output: 0 1 3 2 8
Explanation: Following describes the working of best first search:
- Start at node 0. Among its neighbors, node 1 has the lowest cost (edge cost 3), so move from 0 to 1.
- From node 1, since a better path forward isn’t available, backtrack to node 0.
- From node 0, choose the next best neighbor—node 3 (edge cost 5)—and move to node 3.
- At node 3, find that moving to node 2 leads to a lower incremental cost.
- Then proceed from node 2 to node 8 (the target)