itslabtime.com

Information · Computing · Algorithm Exploration

Shortest paths and graph search

The criterion of “shortest” can be based on the number of moves, or the sum of costs. If the edge costs differ, then the length of the shortest path and the minimum cost length will change.

Related experiment: Finding shortest paths →
Finding shortest paths
Finding shortest paths: simulation view →

Meaning and mechanism

The graph represents positions as vertices, and movable relationships as edges. The cost of a path is defined as the sum of the costs of the edges traversed or the costs assigned to each vertex.

Width-first search expands based on the number of moves on edges with equal costs. Dijkstra’s algorithm selects candidates based on the current minimum accumulated cost.

Relationships and conditions

Relaxation updates d(v) to min(d(v),d(u)+w(u,v)). When a cheaper path is found, both the distance and predecessor information are updated.

The standard procedure for Dijkstra’s algorithm relies on the condition that there are no negative weights. The experiment uses only up, down, left, and right movements, with positive costs, while diagonal or actual road restrictions are omitted.

What to observe in the simulation

BFS minimizes steps; Dijkstra minimizes total cost.

Moves are orthogonal and costs positive. Reproducible presets set walls and endpoints.

Key relationships and symbols

d(v) = min[d(u) + w(u,v)]

Symbols and units used in the formulas
SymbolMeaningUnit
d(v)Current distance estimate from the start to vCost
w(u,v)Cost of moving from u to vCost

Worked example

With equal costs, how do the shortest distances compare?

Equal · BFS minimizes steps; Dijkstra minimizes total cost.

Common misconceptions

  • It is not the case that width-first search minimizes the cost for all graphs with different edge weights.

Explore this concept through experiments

References

OpenStax · Introduction to Computer Science (English)