Convert function from recursion to iteration

后端 未结 4 763
耶瑟儿~
耶瑟儿~ 2021-01-01 06:19

I have this function that I wrote that is abysmally slow since php does not handle recursion well. I am trying to convert it to a while loop, but am having trouble wrapping

4条回答
  •  误落风尘
    2021-01-01 06:56

    This looks like your trying to find the optimal route for traversal of a series of nodes in a graph.

    I'm guessing that you've not studied Computer Science as the "Travelling Salesman" problem is an archetype of Artificial Intelligence. Of course, as such, it has its own Wikipedia page:

    http://en.wikipedia.org/wiki/Travelling_salesman_problem

    Sorry - but just swapping from a recursive to an iterative function isn't going to make it go any faster ("php does not handle recursion well." - can you provide reference for this assertion). If you need a faster solution then you'll need to look at non-exhaustive/fuzzy methods.

    C.

提交回复
热议问题