Walkthrough
How Graph Algorithms Work
Step-by-step from graph representation to traversal
Graph Representation
A graph G = (V, E) consists of vertices (nodes) connected by edges. Graphs can be directed (one-way) or undirected (two-way), weighted or unweighted.
Algorithms
Controls
Algorithm Controls
History
0/0Run an algorithm to see traversal history
Analysis
| Algorithm | Time Complexity | Space Complexity |
|---|---|---|
| BFS | O(V + E) | O(V) |
| DFS | O(V + E) | O(V) |
| Dijkstra | O((V+E) log V) | O(V) |
| A* | O(E) | O(V) |
| Prim | O(E log V) | O(V) |
| Kruskal | O(E log V) | O(V + E) |
| Union Find | O(α(N)) | O(N) |
Practice
Interview Questions
Common questions from top company interviews
Design a social network friend recommendation system using BFS up to 3 hops.
Use BFS limited to depth 3 over the user graph; score mutual friends by intersection size between neighbor sets.
How would you find the shortest path between two nodes in a graph with 10M+ nodes?
Use bidirectional Dijkstra from source and target simultaneously; terminate when frontiers meet and combine paths.
Detect cycles in a dependency graph for a build system with thousands of modules.
Perform DFS with three-color marking (white/gray/black); a back edge to a gray node indicates a cycle.
Design an algorithm to detect communities in an undirected social graph of 100M users.
Use the Girvan-Newman method: iteratively remove edges with highest betweenness centrality; subgraphs that separate are communities.
Coding Challenge
Practice on Terminal
Write and submit your solution, then check achievements
Given a directed graph with N vertices and M edges, determine if the graph contains any cycle. Implement a function that returns true if the graph has a cycle, false otherwise.