How to reverse a graph in linear time?

前端 未结 4 1922
天涯浪人
天涯浪人 2021-02-08 06:46

I know there are two ways to represent my graph: one is using a matrix, and the other one is using a list.

If I use a matrix, I have to flip all the bits in the matrix.

4条回答
  •  忘掉有多难
    2021-02-08 07:10

    I think reversing the graph by traversing the list takes O(V2), since for each vertex you must add or delete (V-1) edges.

    As for Dijkstra's algorithm, as I understand it, if you represent the graph as a matrix or list the algorithm takes O(V2), but some other data structures are faster. The fastest known is a Fibonacci heap, which gives O(E + VlogV).

提交回复
热议问题