Breadth First Search and Depth First Search

后端 未结 11 1733
悲&欢浪女
悲&欢浪女 2020-12-24 02:46

Can anybody give a link for a simple explanation on BFS and DFS with its implementation?

11条回答
  •  感情败类
    2020-12-24 03:06

    Say you have a tree as follows:

    It may be a little confusing because E is both a child of A and F but it helps illustrate the depth in a depth first search. A depth first search searches the tree going as deep (hence the term depth) as it can first. So the traversal left to right would be A, B, D, F, E, C, G.

    A breadth first search evaluates all the children first before proceeding to the children of the children. So the same tree would go A, B, C, E, D, F, G.

    Hope this helps.

提交回复
热议问题