What is better, adjacency lists or adjacency matrices for graph problems in C++?

后端 未结 11 1080
小鲜肉
小鲜肉 2020-11-28 00:41

What is better, adjacency lists or adjacency matrix, for graph problems in C++? What are the advantages and disadvantages of each?

11条回答
  •  难免孤独
    2020-11-28 01:35

    Depending on the Adjacency Matrix implementation the 'n' of the graph should be known earlier for an efficient implementation. If the graph is too dynamic and requires expansion of the matrix every now and then that can also be counted as a downside?

提交回复
热议问题