• recategorized by
4,334 views
1 1 vote
Adacency list is preferred over adjacency matrix when the graph is?

A) planar

B)  Dense

C)  Clique

D)  none of these

1 Answer

0 0 votes

First of all note that Sparse means that you have very few edges, and Dense means many edges, or almost complete graph. In a complete graph you have $n(n−1)/2$ edges, where $n$is the number of nodes.

Now, when we use matrix representation we allocate $n×n$ matrix to store node-connectivity information, e.g., $M[i][j]=1$ if there is edge between nodes ii and jj, otherwise$ M[i][j]=0$.


But if we use adjacency list then we have an array of nodes and each node points to its adjacency list containing ONLY its neighboring nodes.

Now if a graph is sparse and we use matrix representation then most of the matrix cells remain unused which leads to the waste of memory. Thus we usually don't use matrix representation for sparse graphs. We prefer adjacency list.

But if the graph is dense then the number of edges is close to (the complete) $n(n−1)/2$, or to $(n^{2})$ if the graph is directed with self-loops. Then there is no advantage of using adjacency list over matrix.

n terms of space complexity
Adjacency matrix: $O(n^{2})$
Adjacency list: $O(n+m)$
where nn is the number nodes, mm is the number of edges.

When the graph is undirected tree then
Adjacency matrix: $O(n^{2})$
Adjacency list: $O(n+n)$ is $O(n)$ (better than $O(n^{2})$)

When the graph is directed, complete, with self-loops then
Adjacency matrix: $O(n^{2})$
Adjacency list: $O(n+(n^{2}))$ is $O(n^{2})$ (no difference)

And finally, when you implement using matrix, checking if there is an edge between two nodes takes $O(1)$ times, while with an adjacency list, it may take linear time in $O( n)$.

answer is none of these

Position:
Show:

Related questions

5 5 votes
2 answers 2 answers
6.9k
6.9k views
rickeshjohn asked Dec 23, 2015
6,858 views
Two ground stations are connected by a 10Mbps satellite link. The altitude of the satellite is 36,000km and the speed of the signal is 3x108 m/sec. What should be the pac...
1 1 vote
0 0 answers
476
476 views
admin asked Dec 15, 2022
476 views
Consider the following graph.Find closeness centrality of $\text{‘A’}$ node.
1 1 vote
0 0 answers
471
471 views
admin asked Dec 15, 2022
471 views
Consider the following graph.Which nodes form the cliques of size $3?$
8 8 votes
1 answers 1 answer
5.0k
5.0k views
go_editor asked Jun 13, 2016
5,019 views
Consider the graph shown in the figure below:Which of the following is a valid strong component?$a, c, d$$a, b, d$$b, c, d$$a, b, c$