开发者

How to convert from recursive algorithm to iterative [closed]

开发者 https://www.devze.com 2023-04-10 17:14 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

How do I convert following recursive algorithm to iterative

DFS-Visit(U)
    color[u] = GREY 
    d[u]  =time
    time = time + 1
    for each v = Adj[u] do 
        if color[v] = WHITE
  开发者_开发技巧          then p[v] = u
                DFS-Visit(v)
    color[u] = BLACK
    f[u] = time
    time = time + 1


USE stack to save the state instead..of calling it recursively

this might help you : http://www.cs.mcgill.ca/~pnguyen/251F09/DFS.pdf

0

精彩评论

暂无评论...
验证码 换一张
取 消