Graph Theory Explorer
Build a graph interactively, then watch BFS, DFS, Dijkstra's shortest path or Prim's MST animate node by node. Click empty space to add nodes, drag between nodes to connect them, right-click to delete.
Click canvas to add nodes. Drag from one node to another to add an edge. Right-click node/edge to delete. Then click a node to set start and press Run.
How It Works
A graph G = (V, E) consists of a set of vertices (nodes) and edges connecting them. This explorer lets you build undirected weighted graphs and visualize four fundamental algorithms:
Breadth-First Search (BFS)
Explores all neighbours at distance 1, then distance 2, etc. Uses a queue (FIFO). Finds the shortest path in terms of hop count in unweighted graphs. Time complexity: O(V + E).
Depth-First Search (DFS)
Explores as far as possible along each branch before backtracking. Uses a stack (implicit via recursion or explicit). Useful for cycle detection, topological sorting, and connected components. Time: O(V + E).
Dijkstra's Shortest Path
Finds the shortest weighted path from a source to all other nodes. Uses a priority queue and relaxes edges greedily. Works on non-negative weights. Time: O((V + E) log V).
Prim's Minimum Spanning Tree
Builds the minimum spanning tree — the lightest set of edges connecting all nodes. Grows the tree greedily by always picking the cheapest edge crossing the cut between tree and non-tree nodes.