Dijkstra's Algorithm Simulator

Simulate Dijkstra's algorithm to find shortest paths from a starting node in a weighted graph. Enter the graph and start node to get started.

Dijkstra's Algorithm Simulator

Please enter valid graph data and start node.

Shortest Paths

Result will appear here

Result copied to clipboard!

About the Dijkstra's Algorithm Simulator

The Dijkstra's Algorithm Simulator computes the shortest paths from a starting node to all other nodes in a weighted directed graph with non-negative edge weights. This tool is designed for computer science students, developers, and educators studying graph algorithms.

Dijkstra's Algorithm: Finds the shortest paths by maintaining a priority queue of nodes, updating distances as it explores the graph greedily.

This simulator is ideal for learning graph algorithms, network routing, and competitive programming.

  • Features:
    • Simulates Dijkstra's algorithm on a user-defined directed graph.
    • Supports adjacency list input (e.g., \( u \\to v, w \)) for edges.
    • Keypad includes digits (0–9), comma (,), and arrow (->) for graph input.
    • Validates graph data and start node, ensuring non-negative weights.
    • Clear and backspace functionality, with a "Copy" button for results.
    • Displays step-by-step execution with distances and predecessors.
  • Practical Applications: Useful in network routing (e.g., GPS navigation), graph analysis, and algorithm education.
  • How to Use:
    • Enter the number of nodes (\( n \)).
    • Enter edges in the format \( u \\to v, w \) (one per line), where \( u \) and \( v \) are node indices (0-based) and \( w \) is the edge weight.
    • Enter the start node (0-based index).
    • Use the keypad to input digits, commas, and arrows for edges.
    • Click "Run" to compute shortest paths, then use "Copy" to copy the result.
    • Use "Clear" to reset or "⌫" to delete the last character.
    • Share or embed the simulator using the action buttons.
  • Helpful Tips:
    • Node indices are 0-based (0 to \( n-1 \)).
    • Edge weights must be non-negative integers.
    • Ensure the start node is valid (0 to \( n-1 \)).
    • Use the comma (,) and arrow (->) buttons for consistent edge formatting.
    • Results show distances and predecessors for each node.
    • Limit graph size (\( n \leq 100 \), edges \( \leq 1000 \)) for performance.
  • Examples:
    • Example 1: Simple Graph:
      • Input: \( n = 4 \), Edges = \( 0\\to1,5 \), \( 0\\to2,3 \), \( 1\\to2,2 \), \( 1\\to3,6 \), \( 2\\to3,2 \), Start Node = 0
      • Steps:
        • Initialize distances: \( d[0] = 0 \), others \( \\infty \).
        • Process node 0: Update \( d[1] = 5 \), \( d[2] = 3 \).
        • Process node 2: Update \( d[3] = 5 \).
        • Process node 1: Update \( d[3] = 5 \) (no change).
        • Process node 3: No updates.
      • Result: Distances = \( [0, 5, 3, 5] \), Predecessors = \( [-, 0, 0, 2] \)
    • Example 2: Disconnected Node:
      • Input: \( n = 3 \), Edges = \( 0\\to1,2 \), \( 1\\to2,3 \), Start Node = 0
      • Steps:
        • Initialize distances: \( d[0] = 0 \), others \( \\infty \).
        • Process node 0: Update \( d[1] = 2 \).
        • Process node 1: Update \( d[2] = 5 \).
        • Process node 2: No updates.
      • Result: Distances = \( [0, 2, 5] \), Predecessors = \( [-, 0, 1] \)
    • Example 3: Single Node:
      • Input: \( n = 1 \), Edges = (none), Start Node = 0
      • Steps:
        • Initialize distances: \( d[0] = 0 \).
        • No edges to process.
      • Result: Distances = \( [0] \), Predecessors = \( [-] \)

Simulate Dijkstra's algorithm with detailed steps using this tool. Share or embed it on your site!

Have Suggestions?

We value your feedback! Share your ideas to help us improve the Dijkstra's Algorithm Simulator.