1 / 15

Elements of dynamic programming

Elements of dynamic programming. 15.3. Optimal substructure.

ellery
Download Presentation

Elements of dynamic programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Elements of dynamic programming 15.3

  2. Optimal substructure • The first step in solving an optimization problem by dynamic programming is to characterize the structure of an optimal solution. Recall that a problem exhibits optimal substructure if an optimal solution to the problem contains within it optimal solutions to subproblems.

  3. Characterize the space of subproblems • a good rule of thumb is to try to keep the space as simple as possible, and then to expand it as necessary. • For example: • the space of subproblems that we considered for assembly-line scheduling was the fastest way from entry into the factory through stations S1, jand S2, j. This subproblemspace worked well, and there was no need to try a more general space of subproblems.

  4. Optimal substructure • Optimal substructure varies across problem domains in two ways: 1. how many subproblems are used in an optimal solution to the original problem, and 2. how many choices we have in determining which subproblem(s) to use in an optimal solution.

  5. Assembly-line scheduling • In assembly-line scheduling, an optimal solution uses just one subproblem, but we must consider two choices in order to determine an optimal solution. To find the fastest way through station Si, j, we use either the fastest way through S1, j−1or the fastest way through S2, j−1; whichever we use represents the one subproblem that we must optimally solve.

  6. Running time of a dynamic-programming • Informally, the running time of a dynamic-programming algorithm depends on the product of two factors: the number of subproblems overall and how many choices we look at for each subproblem. In assembly-line scheduling, we had Theta (n) subproblemsoverall, and only two choices to examine for each, yielding a Theta (n) running time.

  7. Be careful • One should be careful not to assume that optimal substructure applies when it does not. • Unweightedshortest path:2 Find a path from u to v consisting of the fewest edges. Such a path must be simple, since removing a cycle from a path produces a path with fewer edges. • Unweighted longest simple path: Find a simple path from u to v consisting of the most edges. We need to include the requirement of simplicity because otherwise we can traverse a cycle as many times as we like to create paths with an arbitrarily large number of edges. • A path is called simple if it does not have any repeated vertices.

  8. Not simple

  9. read only • Overlapping subproblems • Reconstructing an optimal solution • Memoization • 15.4 Longest common subsequence

  10. 15.5 Optimal binary search trees • Suppose that we are designing a program to translate text from English to French. • For each occurrence of each English word in the text, we need to look up its French equivalent. One way to perform these lookup operations is to build a binary search tree with n English words as keys and French equivalents as satellite data.

More Related