Shortest Path with a Constraint (Modified Dijkstra/Bellman-Ford)

viaGlassdoor

Problem: Implement a shortest-path algorithm over a graph subject to a specific additional constraint (e.g. a limit on number of edges/stops, or an extra cost dimension), requiring modification of a classical shortest-path algorithm.

Approach: Extend Dijkstra's algorithm (for non-negative weights) or Bellman-Ford (if negative weights/constraint requires relaxing more states) by augmenting the state with the constraint dimension (e.g. state = (node, constraint-used-so-far)) so that the relaxation step respects the extra limit, rather than tracking only the plain shortest distance to each node.

Add a follow-up question they asked
No follow-ups yet. Be the first to add one.
asked …
LeaderboardSalary
Language
Account