Dijkstra Shortest Path Calculator

Enter a 4Γ—4 adjacency matrix. Leave blanks or enter - for no edge.

Fill in the matrix and nodes.

Dijkstra's Algorithm in Brief

Dijkstra's algorithm finds the least costly path between a starting node and all other nodes in a weighted graph with nonnegative edge weights. It maintains a set of nodes whose minimal distance from the start is known and repeatedly selects the closest unexplored node to update its neighbors. The pseudocode can be summarized as a repeated relaxation step where tentative distances decrease until convergence.

The cost updates follow the rule dvnew=mindvold,du+wuv, where wuv is the weight of edge uv. Because all weights are nonnegative, once a node is chosen as the closest, its distance is final.

Using This Calculator

Fill the 4Γ—4 matrix with distances between nodes. Use blank fields or negative numbers to represent missing edges. Specify start and end nodes using zero-based indexing. When you click the compute button, the script runs Dijkstra's algorithm and outputs the total length and the path taken.

Example

Imagine a graph with edges 0β†’1 of weight 2, 1β†’2 of weight 3, and 0β†’2 of weight 10. The algorithm explores node 0 first, then node 1, ultimately discovering that the cheapest path from 0 to 2 goes through 1 with total cost 5. You can verify this by entering appropriate numbers in the matrix.

Broader Context

Dijkstra's method is a fundamental building block in network routing, logistics, and geographic mapping. Although the basic version presented here handles only four nodes, the same idea scales to huge graphs and remains efficient when implemented with priority queues. Understanding the algorithm's stepwise improvement of tentative distances builds intuition for more advanced techniques such as A* search and Bellman–Ford for graphs with negative edges.

Related Calculators

Linear Diophantine Equation Solver - Find Integer Solutions

Solve equations of the form ax + by = c for integers x and y using the extended Euclidean algorithm.

linear diophantine equation calculator ax + by = c solver

Jacobian Matrix Calculator - Partial Derivatives at a Point

Compute the 2x2 Jacobian matrix of two functions of two variables using symbolic differentiation.

Jacobian matrix calculator partial derivatives

Discrete Convolution Calculator - Combine Sequences Easily

Compute the discrete convolution of two finite sequences for signal processing and probability.

discrete convolution calculator sequence convolution signal processing