Find the shortest path between two vertices in an undirected graph

Program to find the shortest path between two vertices in an undirected graph is discussed here. Given a graph, find the shortest path between the given source and destination nodes.

For example, consider the graph given below. We have to find the shortest path between vertices 1 and 5.

shortest path between two vertices in a graph

1 -> 0 -> 4 -> 5

1 -> 0 -> 2 -> 5

1 -> 2 -> 5

Shortest path: 1 -> 2 -> 5

Number of edges: 2

Last updated