graph algo
graph algo
3. Dijkstra’s Algorithm
● Purpose: Finds the shortest path between nodes in a graph with non-negative edge
weights.
● Time Complexity: O(V2)O(V^2)O(V2) (with adjacency matrix), O((V+E)logV)O((V + E)
\log V)O((V+E)logV) (with adjacency list and min-heap)
● Space Complexity: O(V+E)O(V + E)O(V+E)
● Use Cases: GPS navigation systems, network routing protocols.
● Remarks: Cannot handle negative weight edges.
4. Bellman-Ford Algorithm
● Purpose: Finds the shortest path from a single source to all other vertices in a graph.
● Time Complexity: O(VE)O(VE)O(VE)
● Space Complexity: O(V)O(V)O(V)
● Use Cases: Finding shortest paths in graphs with negative weight edges, used in routing
protocols like RIP.
● Remarks: Can detect negative weight cycles.
5. Floyd-Warshall Algorithm
6. Kruskal’s Algorithm
7. Prim’s Algorithm
8. A* Search Algorithm
● Purpose: Finds the shortest path between nodes in a weighted graph using heuristics.
● Time Complexity: O(E)O(E)O(E) (in the worst case)
● Space Complexity: O(V)O(V)O(V)
● Use Cases: Pathfinding in games, robot motion planning.
● Remarks: Uses heuristics to improve efficiency over Dijkstra’s algorithm.
9. Topological Sort