What is time complexity of BFS depending on the representation of the graph?

后端 未结 4 1245
野性不改
野性不改 2021-02-04 15:15

I was wondering what is the time complexity of BFS, if I use:

  • an adjacency matrix
  • adjacency list
  • edge list

Is it same as their spa

4条回答
  •  遥遥无期
    2021-02-04 15:28

    Time complexity necessarily depends on the representation.

    As this link suggests, the time complexity with and adjacency list is O(V + E), and with an adjacency matrix is O(V2).

提交回复
热议问题