Ahsan Ahmad
Ahsan Ahmad

Reputation: 11

I am confused between shortest path finding algorithm and graph traversing algorithm

My understanding is that BFS and DFS are graph traversing algorithm while other algorithms like A* and dijkstra are for finding shortest path between two nodes of a graph. But in some places, I see BFS and DFS also stated as shortest path finding algorithm. Please elaborate the difference between graph traversing algorithm and shortest path finding algorithm. Thanks!

Upvotes: 0

Views: 311

Answers (1)

"Graph traversal" is any algorithm that iterates over nodes. "Shortest path" means finding the shortest path between two nodes.

Your confusion probably comes from the fact that BFS, a graph traversal algorithm, can also be used to find the shortest path in unweighted graphs. Also, both BFS and DFS find the shortest path in trees (since there's always only one path between nodes)

Upvotes: 0

Related Questions