Shortest Path Concept & Pattern
Original12/26/25Less than 1 minute
🧠 Concept
Usually, the shortest path refers to the minimal sum of path weights for weighted graph
Single-source shortest path
- Find the shortest path from one starting point to all other nodes
- The output of a single-source shortest path algorithm is usually a one-dimensional array
distTo, wheredistTo[i]means the shortest path length from the start node to nodei
Point-to-point shortest path
- Find the shortest path from a start node
srcto a target nodedst - A special case of the single-source shortest path problem, stopped when reach
dst, or - A* Algorithm
- Find the shortest path from a start node
All pairs shortest path
- Find the shortest paths between any two nodes in a graph
- The final output of an all-pairs shortest path algorithm is a 2D array
dist, wheredist[i][j]means the shortest path length from nodeito nodej - Sometimes, using Floyd is more efficient. Sometimes, running Dijkstra multiple times is better.
