Optimal substructure: Difference between revisions

Content deleted Content added
Simplifying example and expanding it by giving an example of the opposite case
Line 9:
Consider finding a [[Shortest path problem|shortest path]] for travelling between two cities by car, as illustrated in Figure 1. Such an example is likely to exhibit optimal substructure. That is, if the shortest route from Seattle to Los Angeles passes through Portland and then Sacramento, then the shortest route from Portland to Los Angeles must pass through Sacramento too. That is, the problem of how to get from Portland to Los Angeles is nested inside the problem of how to get from Seattle to Los Angeles. (The wavy lines in the graph represent solutions to the subproblems.)
 
As an example of a problem that is unlikely to exhibit optimal substructure, consider the problem of finding the cheapest airline ticket from Buenos Aires to Moscow. Even if that ticket involves stops in Miami and then London, we can't conclude that the cheapest ticket from Miami to Moscow stops in London, because airlinesthe sellprice aat multi-flightwhich tripsan atairline sells a pricemulti-flight whichtrip is usually not the sum of the prices ofat eachwhich flightit would sell the individual flights in the trip.
 
 
==Definition==