开发者

what is the worst-case running time for finding two given vertices are adjacent in Adjacency matrix implmentation of a graph

开发者 https://www.devze.com 2023-03-02 17:49 出处:网络
What is the worst-case running time for finding two given vertices are adjacent in Adjacency matrix implmentation of a graph? Is that not O(1) as I know the indices of those vertices in the matrix so

What is the worst-case running time for finding two given vertices are adjacent in Adjacency matrix implmentation of a graph? Is that not O(1) as I know the indices of those vertices in the matrix so that I can pick the value in constant time开发者_开发知识库? I read it as O(n^2) in a book. Someone please explain it how to get to this measure.

Thanks


An adjacency matrix occupies O(n^2) memory, which may be where you're confused. But yes lookup given two vertices is O(1), that's the advantage of an adjacency matrix.


yes. it is O(1) for the reasons stated by you.

0

精彩评论

暂无评论...
验证码 换一张
取 消