search

Home  >  Q&A  >  body text

算法 - 用代码获取流程走向(Java)

需求是这样的,有很多类似的流程如下:

有一个函数,我传入一个开始节点Node,能够获取所有的流程走向,包装List返回,比如上面这张图就有两种走向:通过和不通过。我开始用递归来做,类似这样:

测试了几个流程,确实能达到效果,但是一遇到复杂的流程(上百种走向)的时候,

递归就会有性能问题(栈溢出等)
请问各位大神,像这种情况除了递归还有什么解法吗?如果没有,这种递归有哪里可以优化的地方?小弟能力有限,想了几天没啥好办法....

天蓬老师天蓬老师2813 days ago579

reply all(2)I'll reply

  • 阿神

    阿神2017-04-18 10:54:54

    1. The problem is recursive, and recursion is not necessary for implementation. You can put "Node that has not yet been searched" into a List. Each time a new Node is found, it is placed at the end of the List. When the next round of search starts, it is taken from the end of the List.

    2. Dynamic programming should also be used to reduce repeated searches. This problem is NP in complete search.

    reply
    0
  • 迷茫

    迷茫2017-04-18 10:54:54

    Is this a workflow? ? ? ?

    reply
    0
  • Cancelreply