● V = number of vertices
● E = number of edges
● logV = logarithm of V
● For weighted graphs: assume edge weights are integers or real numbers.
1. BFS (Breadth-First Search)
● Time: O(V + E)
● Space: O(V) (for visited array + queue)
2. DFS (Depth-First Search)
● Time: O(V + E)
● Space: O(V) (recursion stack + visited array)
3. Topological Sort using DFS
● Time: O(V + E)
● Space: O(V) (stack + visited array)
4. Topological Sort using BFS (Kahn’s Algorithm)
● Time: O(V + E)
● Space: O(V) (in-degree array + queue)
5. SCC using Kosaraju’s Algorithm
● Time: O(V + E)
● Space: O(V + E) (graph + transpose graph + visited)
6. Articulation Point & Bridge using Tarjan’s Algorithm
● Time: O(V + E)
● Space: O(V) (discovery time, low time, parent arrays)
7. Dijkstra’s Algorithm
● Time:
○ Using min-heap (binary heap): O((V + E) log V)
○ Using Fibonacci heap: O(E + V log V) (theoretically better but rarely used in
practice)
● Space: O(V) (distance array + min-heap)
8. Bellman-Ford Algorithm
● Time: O(V * E)
● Space: O(V) (distance array)
9. Prim’s Algorithm
● Time:
○ Using min-heap: O((V + E) log V)
○ Using adjacency matrix: O(V^2)
● Space: O(V) (priority queue + MST set)
10. Kruskal’s Algorithm
● Time: O(E log E) (or O(E log V) if using Union-Find with path compression)
● Space: O(V) (for Union-Find structure)
11. Floyd-Warshall Algorithm
● Time: O(V^3)
● Space: O(V^2) (distance matrix)
12. Johnson’s Algorithm
● Time: O(V * E + V log V)
○ Uses Bellman-Ford (O(V * E)) + Dijkstra from every node (O(V * (E + V
log V)))
● Space: O(V^2) (distance matrix)