I am trying to list down all of the commonly used/asked graph algorithms that are asked on coding interviews.
Here is what I found so far.
- DFS: Tonnes of problems on Leetcode
- BFS: Tonnes of problems on Leetcode
- Union Find: Tonnes of problems on Leetcode
- Topological Sorting:
- Single/Multi-source Shortest Path: Dijkstra, Bellman, Floyd-Warshall algorithm. Leetcode has good amount of problems on this topic. Few are following
- Minimum Spanning Trees: Prim’s and Kruskal’s algorithm.
- Strongly Connected Components: Tarjan’s Algorithm
- Hierholzer’s algorithm for Eulerian circuits.
- A* Search
- Max-Flow, Min-Cut
- Articulation points and bridges
Those are the main concepts and algorithms that I found after solving around 500 LC. But I am sure there’s more. Can you please help me to list down all of the important graph algorithms and concepts that someone needs to know to handle any graph related problem gracefully?
Please put a comment mentioning the algorithms and concepts along with a link of any LC (at least one LC problem link) that can be solved with that. I will update the post accordingly.
Adding a few more:
MST (minimum spanning tree), which can be built using Kruskal’s or Prim’s
1489 https://leetcode.com/problems/find-critical-and-pseudo-critical-edges-in-minimum-spanning-tree/
Floyd-Warshall
1334 https://leetcode.com/problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/
399 https://leetcode.com/problems/evaluate-division/
787 https://leetcode.com/problems/cheapest-flights-within-k-stops/
1462 https://leetcode.com/problems/course-schedule-iv/
1617 https://leetcode.com/problems/count-subtrees-with-max-distance-between-cities/
Also Hierholzer’s algorithm for Eulerian circuits: https://leetcode.com/problems/reconstruct-itinerary/
The bus routes question is multi start bfs question https://leetcode.com/problems/bus-routes/
Also if you look at the bfs section, some of them will be shortest path. Sort by hard, you’ll find them. Also if you do a question, the recommended questions are usually also relevant
1. BFS
2. DFS
3. Dijkstra
4. Bell man ford
5. Floyd- warshall
6. Kosarajus
7. Tarjans
8. Disjoint set (Union-Find)
9. Topological sort
10. Flood Fill algo
11. Prims
12. Kruskals
13. Trie
14. Euler's and Hamilton's algo
15. Ford-Fulkerson Algorithm