All paths of length L from node n using python

前端 未结 5 1411
伪装坚强ぢ
伪装坚强ぢ 2020-12-16 07:34

Given a graph G, a node n and a length L, I\'d like to collect all (non-cyclic) paths of length L that depart from n.

Do you have any idea on how to approach this?

5条回答
  •  天命终不由人
    2020-12-16 08:27

    Use a depth limited search (http://en.wikipedia.org/wiki/Depth-limited_search) where you keep a set of visited nodes for the detection of a cycle when on a path. For example you can build a tree from your node n with all nodes and length of L then prune the tree.

    I did a quick search of graph algorithms to do this, but didn't find anything. There is a list of graph algorithms (http://en.wikipedia.org/wiki/Category:Graph_algorithms) that may have just what you are looking for.

提交回复
热议问题