This set of Data Structure Multiple Choice Questions & Answers (MCQs) focuses on “Adjacency List”.

1. Space complexity for an adjacency list of an undirected graph having large values of V (vertices) and E (edges) is ___________

a) O(E)

b) O(V*V)

c) O(E+V)

d) O(V)

View Answer

Explanation: In an adjacency list for every vertex there is a linked list which have the values of the edges to which it is connected.

2. For some sparse graph an adjacency list is more space efficient against an adjacency matrix.

a) True

b) False

View Answer

Explanation: Space complexity for adjacency matrix is always O(V*V) while space complexity for adjacency list in this case would be O(V).

3. Time complexity to find if there is an edge between 2 particular vertices is _________

a) O(V)

b) O(E)

c) O(1)

d) O(V+E)

View Answer

Explanation: The maximum edges a vertex can have is V-1.

4. For the given conditions, which of the following is in the correct order of increasing space requirement?

i) Undirected, no weight

ii) Directed, no weight

iii) Directed, weighted

iv) Undirected, weighted

a) ii iii i iv

b) i iii ii iv

c) iv iii i ii

d) i ii iii iv

View Answer

Explanation: i) takes v+4e, ii) takes v+2e, iii) takes v+3e, iv) takes v +6e space.

5. Space complexity for an adjacency list of an undirected graph having large values of V (vertices) and E (edges) is __________

a) O(V)

b) O(E*E)

c) O(E)

d) O(E+V)

View Answer

Explanation: In an adjacency list for every vertex there is a linked list which have the values of the edges to which it is connected.

6. Complete the given snippet of code for the adjacency list representation of a weighted directed graph.

class neighbor { int vertex, weight; ____ next; } class vertex { string name; _____ adjlist; } vertex adjlists[101];

a) vertex, vertex

b) neighbor, vertex

c) neighbor, neighbor

d) vertex, neighbor

View Answer

Explanation: Vertex would have a name and a linked list attached to it.

7. In which case adjacency list is preferred in front of an adjacency matrix?

a) Dense graph

b) Sparse graph

c) Adjacency list is always preferred

d) Complete graph

View Answer

Explanation: In case of sparse graph most of the entries in the adjacency matrix would be 0, hence adjacency list would be preferred.

8. To create an adjacency list C++’s map container can be used.

a) True

b) False

View Answer

Explanation: We can create a mapping from string to a vector, where string would be the name of the vertex and vector would contains the name of the vertices to which it is connected.

9. What would be the time complexity of the following function which adds an edge between two vertices i and j, with some weight ‘weigh’ to the graph having V vertices?

vector<int> adjacent[15] ; vector<int> weight[15]; void addEdge(int i,int j,int weigh) { adjacent[a].push_back(i); adjacent[b].push_back(j); weight[a].push_back(weigh); weight[b].push_back(weigh); }

a) O(1)

b) O(V)

c) O(V*V)

d) O(log V)

View Answer

Explanation: The function win in the constant time as all the four step takes constant time.

10. What would be the time complexity of the BFS traversal of a graph with n vertices and n^{1.25} edges?

a) O(n)

b) O(n^{1.25})

c) O(n^{2.25})

d) O(n*n)

View Answer

Explanation: The time complexity for BFS is O(|V| + |E|) = O(n + n

^{1.25}) = O(n

^{1.25}).

**Sanfoundry Global Education & Learning Series – Data Structure.**

To practice all areas of Data Structure, __here is complete set of 1000+ Multiple Choice Questions and Answers__.

**Next Steps:**

- Get Free Certificate of Merit in Data Structure I
- Participate in Data Structure I Certification Contest
- Become a Top Ranker in Data Structure I
- Take Data Structure I Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

**Related Posts:**

- Practice Computer Science MCQs
- Buy Programming Books
- Practice Programming MCQs
- Practice Design & Analysis of Algorithms MCQ
- Apply for Data Structure Internship