Master algorithms for analyzing networks, relationships, and connected data. From basic traversals to advanced pathfinding and network optimization algorithms.
Systematically visit all vertices and edges
Find optimal paths between vertices
Connect all vertices with minimum total weight
Analyze structural properties of graphs
2D array where matrix[i][j] = 1 if edge exists between vertex i and j
Time Complexity: O(1) edge lookup, O(V²) space
Best for: Dense graphs, frequent edge queries
Cons: High space usage, inefficient for sparse graphs
Array of lists where list[i] contains all neighbors of vertex i
Time Complexity: O(degree) edge lookup, O(V + E) space
Best for: Sparse graphs, memory efficiency
Cons: Slower edge existence check
Use BFS for shortest path in unweighted graphs, DFS for cycle detection and topological sorting
Use Dijkstra for non-negative weights, Bellman-Ford when negative edges exist
Use Floyd-Warshall for small dense graphs, run Dijkstra from each vertex for sparse graphs
Use Kruskal for sparse graphs, Prim for dense graphs or when starting vertex matters
Use Topological Sort for dependency resolution and ordering problems
Use SCC algorithms to identify clusters and strongly connected components
Algorithm | Time Complexity | Space Complexity | Graph Type |
---|---|---|---|
BFS / DFS | O(V + E) | O(V) | Any |
Dijkstra | O((V + E) log V) | O(V) | Non-negative weights |
Bellman-Ford | O(V × E) | O(V) | Any weighted |
Floyd-Warshall | O(V³) | O(V²) | Any weighted |
Kruskal | O(E log E) | O(V) | Undirected weighted |
Prim | O(E log V) | O(V) | Undirected weighted |
Visualize networks and see algorithms work on real graph structures