Breadth First Search time complexity analysis

后端 未结 6 1581
说谎
说谎 2020-12-12 16:31

The time complexity to go over each adjacent edge of a vertex is, say, O(N), where N is number of adjacent edges. So, for V numbers of

6条回答
  •  星月不相逢
    2020-12-12 16:43

    Performing an O(1) operation L times, results to O(L) complexity. Thus, removing and adding a vertex from/to the Queue is O(1), but when you do that for V vertices, you get O(V) complexity. Therefore, O(V) + O(E) = O(V+E)

提交回复
热议问题