Dijkstra, Bellman-Ford, Floyd-Warshall, Prim, Kruskal, union-find, topological sort and max flow.
40 cards · basic cards · AI-written, checked twice. Edit anything.
- What is Dijkstra's algorithm?
Show answer
A greedy algorithm for finding the shortest path from a source vertex to all other vertices in a weighted graph with non-negative edge weights.
- What is the time complexity of Dijkstra's algorithm with a binary min-heap?
Show answer
O((V + E) log V), where V is the number of vertices and E is the number of edges.
- Why does Dijkstra's algorithm use a greedy strategy?
Show answer
It always selects the unvisited vertex with the smallest known distance, which guarantees the shortest path to that vertex.
- Can Dijkstra's algorithm handle negative edge weights?
Show answer
No, it fails with negative weights because the greedy choice of the minimum distance vertex may not lead to the true shortest path.
- What is relaxation in Dijkstra's algorithm?
Show answer
The process of updating a vertex's distance if a shorter path is found through another vertex.
- What is the Bellman-Ford algorithm?
Show answer
An algorithm that computes shortest paths from a source vertex to all other vertices in a weighted graph, even with negative edge weights.
- What is the time complexity of the Bellman-Ford algorithm?
Show answer
O(VE), where V is the number of vertices and E is the number of edges.
- What is a key advantage of Bellman-Ford over Dijkstra?
Show answer
Bellman-Ford can handle graphs with negative edge weights.
- How does Bellman-Ford detect negative cycles?
Show answer
By running one additional relaxation pass after V - 1 passes; if any distance improves, a negative cycle exists.
- How many relaxation passes does Bellman-Ford perform to guarantee shortest paths?
Show answer
V - 1 passes, where V is the number of vertices.
- What is the Floyd-Warshall algorithm?
Show answer
A dynamic programming algorithm that computes the shortest paths between all pairs of vertices in a weighted graph.
- What is the time complexity of Floyd-Warshall?
Show answer
O(V^3), where V is the number of vertices.
- Why is Floyd-Warshall called an all-pairs shortest path algorithm?
Show answer
It computes the shortest distance between every pair of vertices in the graph.
- What does the intermediate vertex k represent in Floyd-Warshall's recurrence?
Show answer
The algorithm considers paths from vertex i to vertex j that pass through only vertices 0 to k.
- Can Floyd-Warshall detect negative cycles?
Show answer
Yes, by checking if any diagonal element in the final distance matrix is negative.