Question: Write a function to find the shortest path between two nodes in a graph. The function should take in the graph, represented as an adjacency
Write a function to find the shortest path between two nodes in a graph. The function should take in the graph, represented as an adjacency list, and the starting and ending nodes, and return the shortest path as a list of nodes. The function should first use breadth-first search to find the shortest path and then return the list of nodes in the path.
Example:
Input:
graph = {
"A": ["B", "C"],
"B": ["A", "D", "E"],
"C": ["A", "F"],
"D": ["B"],
"E": ["B", "F"],
"F": ["C", "E"]
}
start = "A"
end = "F"
Output: ["A", "C", "F"]
Step by Step Solution
3.52 Rating (159 Votes )
There are 3 Steps involved in it
The detailed ... View full answer
Get step-by-step solutions from verified subject matter experts
