Does this python code employs Depth First Search (DFS) for finding all paths?

后端 未结 3 1815
执笔经年
执笔经年 2021-01-15 02:20

This code is given in python official essays on graph theory. Here\'s the code:

def find_all_paths(graph, start, end, path=[]):
        path = path + [start]         


        
3条回答
  •  心在旅途
    2021-01-15 03:15

    Yes, this algorithm is indeed a DFS. Notice how it recurses right away (go into the child) when looping over the various nodes, as opposed to a Breadth First Search which would basically make a list of viable nodes (e.g. everything on the same level of depth, a.k.a. siblings) and only recursing when those do not match your requirements.

提交回复
热议问题