Explanation of runtimes of BFS and DFS

后端 未结 5 442
你的背包
你的背包 2021-01-30 08:42

Why are the running times of BFS and DFS O(V+E), especially when there is a node that has a directed edge to a node that can be reached from the vertex, like in this example in

5条回答
  •  日久生厌
    2021-01-30 09:29

    It becomes clear when you see a graph as a data structure represented as an adjacent list

    You see Vertices: A,B,C,D,E and adjacent vertices for each Vert/Node as list from those vert. You have to "see" all boxes to check wether it has been "visited" in case of cyclical graph or you just go through all children if it's tree like graph

提交回复
热议问题