– Optimal substructure (โครงสร ้างย่อยที่เหมาะสมที่สุด)
• Such optimal substructures are usually described by means of recursion.
• For example, given a graph G=(V,E), the shortest path p from a vertex u to a
vertex v exhibits optimal substructure: take any intermediate vertex w on this
shortest path p. If p is truly the shortest path, then it can be split into subpaths
p1 from u to w and p2 from w to v such that these, in turn, are indeed the
shortest paths between the corresponding vertices. Hence, one can easily
formulate the solution for finding shortest paths in a recursive manner, which is
what the Bellman–Ford algorithm or the Floyd–Warshall algorithm does.