Visualize Depth-First Search (DFS) on a graph. Watch how the algorithm explores as deep as possible before backtracking.
An interactive graph where you can draw nodes, connect them with weighted edges, and visualize BFS, DFS, and Dijkstra's shortest-path algorithms.
A graph is made of nodes (vertices) connected by edges. Edges carry a weight representing cost or distance. The source node (green) is the algorithm start; target (red) is the goal.
In Draw mode: click the empty canvas to place a node, click a node to select it (purple ring), then click another node to connect them with an edge. Drag any node to reposition it.
BFS explores the graph level-by-level, radiating outward from the source. It visits all neighbors at depth 1 before depth 2, guaranteeing the shortest hop-count path.
Finds the lowest-cost path on a weighted graph. Always picks the unvisited node with the minimum cumulative distance, ignoring expensive detours.
Finds shortest paths from a source on a directed, weighted graph, even with negative edge weights. Relaxes all edges V−1 times. Detects negative-weight cycles. The preset graph has a negative edge (C→D = −2) making A→C→D→E cost 6, cheaper than A→B→D→E = 8.
V = vertices, E = edges. BFS/DFS run in O(V+E). Dijkstra's with a min-heap runs in O((V+E) log V). Bellman-Ford runs in O(V·E) but handles negative weights and detects negative cycles. Dijkstra's cannot.