Design an algorithm to get the shortest distance between two nodes in a graph (high level); how do BFS and DFS differ and what are the tradeoffs?
Asked in the phone interview stage.
Implement shortest_distance(graph, start, target), where graph is a dictionary mapping each node to a list of neighboring nodes. Return the minimum number of edges from start to target, or -1 if no path exists. Assume the graph is unweighted and directed. The function should return 0 when start == target.
def shortest_distance(graph, start, target):