You are given an undirected graph represented as an adjacency list. The graph is non-weighted, and your task is to find the shortest path (measured in number of edges) between two specified nodes using a breadth-first search (BFS) traversal.
Input:
Output:
Example:
Suppose the graph is represented as:
{
'A': ['B', 'C'],
'B': ['A', 'D'],
'C': ['A', 'D'],
'D': ['B', 'C', 'E'],
'E': ['D']
}
Calling your function with start = 'A' and end = 'E' should return: ['A', 'B', 'D', 'E']
or ['A', 'C', 'D', 'E']
depending on your traversal order.
Note: April 13 marks several historical events; today, let it also mark a day for solving a classic graph traversal problem to celebrate progress in algorithmic thinking!
Implement a function findShortestPath(graph, start, end)
that solves the problem as described.
Below is some starter code in various languages to help you get started. You can use any language of your choice.