Optimal substructure: Difference between revisions

Content deleted Content added
Karroje (talk | contribs)
Added two counter-examples.
mNo edit summary
Line 1:
[[Image:Shortest path optimal substructure.png|200px|thumb|'''Figure 1'''. Finding the shortest path using optimal substructure. Numbers represent the length of the path; straight lines indicate single [[Edge (graph theory)|edges]], wavy lines indicate shortest [[Path (graph theory)|paths]], i.e., there might be other vertices that are not shown here.]]
In در[[computerعلم scienceکامپیوتر]],، aساختاری problemبهینه isاست saidکه toزیرساختارهای آن بهینه باشد.] have '''optimalساختار substructureبهینه''' ifاین ویژگی برای anتعیین optimalسودمندی solutionدر canمسائل beبرنامه¬ constructedنویسی efficientlyپویا fromو optimalالگوریتم solutionsهای toحریصانه itsاستفاده subproblemsمی¬شود.<ref>[http://books.google.com/books?id=NLngYyWFl_YC&pg=PA15&dq=introduction+to+algorithms&psp=1&sig=jX-xfEDWJU3PprUwH8Qfxidli6M#PPP1,M1 Introduction to Algorithms], 2nd ed., (Cormen, Leiserson, Rivest, and Stein) 2001, p. 327. ISBN 0-262-03293-7.</ref> This property is used to determine the usefulness of [[dynamic programming]] and [[greedy algorithm]]s in a problem.
 
Typically, a greedy algorithm is used to solve a problem with optimal substructure if it can be proved by induction that this is optimal at each step (Cormen et al. pp.&nbsp;381–2). Otherwise, providing the problem exhibits [[overlapping subproblem]]s as well, dynamic programming is used. If there are no appropriate greedy algorithms and the problem fails to exhibit overlapping subproblems, often a lengthy but straightforward search of the solution space is the best alternative.