in DS
1,322 views
1 vote
1 vote

Which of the following gives O(1) complexity if we want to check whether an edge exists between two given nodes in a graph?

  1. Adjacency List
  2. Adjacency Matrix
  3. Incidence Matrix
  4. None of these
in DS
1.3k views

4 Answers

1 vote
1 vote
Adjacency matrix . just check the ijth entry and jith in the matrix entry

2 Comments

What about incidence matrix for it should also take o(1) time
0
0
No it will not. Incidence matrix is a matrix where rows represents vertices and columns edge numbers. We dont know the label of edge between $i$ and $j$ beforehand. So to check whether an edge exists between $i$ and $j$ , we will check each column in worst case to check whether both $i^{th}$ and $j^{th}$ contain 1 in the same column. So worst case complexity will be $O(E)$ in case of incidence matrix.
1
1
0 votes
0 votes
Adjacency matrix,it actually checks the presence of edge btw two nodes
0 votes
0 votes
Adjacency matrix as it is an two dimensional array and array gives random access.
0 votes
0 votes
Option B) Adjacency Matrix is the answer , because only the entry is to be checked in the matrix corresponding to the nodes.