Write a function to find the shortest path between two nodes in a graph. The function should
Fantastic news! We've Found the answer you've been seeking!
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 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"]
Related Book For
Posted Date: