Dijkstra's algorithm
This can be done via Dijkstra's algorithm, dynamic programming, greedy algorithm or graph cuts among others.