zoukankan      html  css  js  c++  java
  • Why longest path problem doesn't have optimal substructure?

    We all know that the shortest path problem has optimal substructure. The reasoning is like below:

    Supppose we have a path p from node u to v, another node t lies on path p: u->t->v ("->" means a path).

    We claim that u->t is also a shortest path from u to t, and t->v is a shortest path from t to v.

    Proof: if there is another path from u to t that is shorter than u->t, we can simply replace u->t with this shorter path in the solution of u->v, resulting in a shorter path than u->v, contradicting the fact that u->v is a shortest path from u to v.

    But why can't we apply similar reasoning to the longest path problem? It's because in the longest path problem there are some constraints imposed on the solution. Suppose u->v is a longest path from u->v, node t lies on it.

    So it's like u->t->v. If there is a longer path from u to t than u->t, if we cut off u->t from u->v and paste in the longer path, this new solution may fail some of the restrictions, for example, it may contains a cycle, which is invalid.

  • 相关阅读:
    12.20个人任务总结
    典型用户和用户场景描述
    12.19冲刺总结
    12月18日任务总结
    构建之法阅读笔记02
    构建之法阅读笔记03
    构建之法阅读笔记01
    软件工程个人作业01
    内容提供者
    Pull解析Xml
  • 原文地址:https://www.cnblogs.com/Antech/p/3659938.html
Copyright © 2011-2022 走看看