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 , where is the weight of edge . Because all weights are nonnegative, once a node is chosen as the closest, its distance is final.
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.
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.
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.
Solve equations of the form ax + by = c for integers x and y using the extended Euclidean algorithm.
Compute the 2x2 Jacobian matrix of two functions of two variables using symbolic differentiation.
Compute the discrete convolution of two finite sequences for signal processing and probability.