What is the Graph Theory Playground?
Quick Answer: An interactive tool to build and explore graphs. Add nodes, connect them with weighted edges, and run Dijkstra's algorithm to find the shortest path from a selected source node to all others. Distances and the shortest-path tree are highlighted visually.
Theory of Graphs and Dijkstra's Algorithm
A graph consists of vertices (nodes) and edges (connections) that may have weights. Dijkstra's algorithm finds the shortest path from a source node to all other nodes in a graph with non‑negative edge weights. It maintains a set of visited nodes and repeatedly selects the unvisited node with the smallest tentative distance, updating neighbors. This playground lets you create a graph by clicking, then see the algorithm in action: the shortest path tree edges turn green, and distances are displayed on nodes.
Step-by-Step Examples
Example 1: Simple Shortest Path
- Click "Add Node Mode" and click on the canvas to place 4-5 nodes.
- Switch to "Connect Mode". Click on one node, then another to create a weighted edge (random weight 1-10). Build a small network.
- Click "Select Source", then click a node to set it as the start.
- Click "Run Dijkstra". The shortest distances appear on nodes, and the edges forming the shortest path tree are highlighted in green.
Example 2: Unweighted Graph (BFS)
- Create edges but set all weights to 1 (manually edit? No, they are random. But for unweighted, you can imagine all weights=1; Dijkstra still works as BFS).
- Run Dijkstra; the algorithm will find the path with fewest edges if weights are equal.
Frequently Asked Questions
How do I add nodes and edges?
Use "Add Node Mode" and click canvas. Switch to "Connect Mode", click two nodes to link them. Edge weight is randomly assigned between 1 and 10.
Can I change edge weights?
Not directly in this version; weights are random. You can delete an edge by clicking it in Connect Mode (it will toggle removal).
What does Dijkstra's algorithm do here?
It computes the minimum distance from the selected source node to all reachable nodes, and colors the shortest-path tree edges green.
How do I move a node?
Drag any node with the mouse (in any mode except while connecting). Position updates automatically.
Is negative weight supported?
No, Dijkstra requires non‑negative weights. This tool uses positive random weights only.