How would you find the shortest path between two nodes in a graph? Write code in Java to do this.
Anonimo
This problem, if asked vaguely, aims to test the interviewer's knowledge of ALL shortest-path algorithms. For example, if I were the interviewer, I would ask more details about the graph: if the graph is unweighted, then a simple BFS will suffice. If the graph has negative weight, then dijkstra won't work. If this shortest-path query is going to appear multiple times, use Floyd-Warshall. If there is negative weight, or parallel computing is available, then Bellman-ford.