Engineering Questions with Answers - Multiple Choice Questions

# Data Structure MCQ – Adjacency Matrix

1 - Question

The number of elements in the adjacency matrix of a graph having 7 vertices is __________
a) 7
b) 14
c) 36
d) 49

Explanation: There are n*n elements in the adjacency matrix of a graph with n vertices.

2 - Question

What would be the number of zeros in the adjacency matrix of the given graph? a) 10
b) 6
c) 16
d) 0

Explanation: Total number of values in the matrix is 4*4=16, out of which 6 entries are non zero.

3 - Question

Adjacency matrix of all graphs are symmetric.
a) False
b) True

Explanation: Only undirected graphs produce symmetric adjacency matrices.

4 - Question

The time complexity to calculate the number of edges in a graph whose information in stored in form of an adjacency matrix is ____________
a) O(V)
b) O(E2)
c) O(E)
d) O(V2)

Explanation: As V entries are 0, a total of V2-V entries are to be examined.

5 - Question

For the adjacency matrix of a directed graph the row sum is the _________ degree and the column sum is the ________ degree.
a) in, out
b) out, in
c) in, total
d) total, out

Explanation: Row number of the matrix represents the tail, while Column number represents the head of the edge.

6 - Question

What is the maximum number of possible non zero values in an adjacency matrix of a simple graph with n vertices?
a) (n*(n-1))/2
b) (n*(n+1))/2
c) n*(n-1)
d) n*(n+1)

Explanation: Out of n*n possible values for a simple graph the diagonal values will always be zero.

7 - Question

On which of the following statements does the time complexity of checking if an edge exists between two particular vertices is not, depends?
a) Depends on the number of edges
b) Depends on the number of vertices
c) Is independent of both the number of edges and vertices
d) It depends on both the number of edges and vertices

Explanation: To check if there is an edge between to vertices i and j, it is enough to see if the value of A[i][j] is 1 or 0, here A is the adjacency matrix.

8 - Question

In the given connected graph G, what is the value of rad(G) and diam(G)?
a) 2, 3
b) 3, 2
c) 2, 2
d) 3, 3

Explanation: Value of eccentricity for vertices A, C is 2 whereas for F, B, D, E it is 3.

9 - Question

Which of these adjacency matrices represents a simple graph?
a) [ [1, 0, 0], [0, 1, 0], [0, 1, 1] ]
b) [ [1, 1, 1], [1, 1, 1], [1, 1, 1] ]
c) [ [0, 0, 1], [0, 0, 0], [0, 0, 1] ]
d) [ [0, 0, 1], [1, 0, 1], [1, 0, 0] ]

Explanation: A simple graph must have no-self loops, should be undirected.

10 - Question

Given an adjacency matrix A = [ [0, 1, 1], [1, 0, 1], [1, 1, 0] ], The total no. of ways in which every vertex can walk to itself using 2 edges is ________
a) 2
b) 4
c) 6
d) 8

Explanation: A2 = [ [2, 1, 1], [1, 2, 1], [1, 1, 2] ], all the 3 vertices can reach to themselves in 2 ways, hence a total of 3*2, 6 ways.

11 - Question

If A[x+3][y+5] represents an adjacency matrix, which of these could be the value of x and y.
a) x=5, y=3
b) x=3, y=5
c) x=3, y=3
d) x=5, y=5

Explanation: All adjacency matrices are square matrices.

12 - Question

Two directed graphs(G and H) are isomorphic if and only if A=PBP-1, where P and A are adjacency matrices of G and H respectively.
a) True
b) False

Explanation: This is a property of isomorphic graphs.

13 - Question

Given the following program, what will be the 3rd number that’d get printed in the output sequence for the given input?

```#include <bits/stdc++.h>
using namespace std;
int cur=0;
int G;
bool visited;
deque <int> q;

void fun(int n);

int main()
{
int num=0;
int n;
cin>>n;

for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
cin>>G[i][j];

for(int i=0;i<n;i++)
visited[i]=false;

fun(n);
return 0;
}

void fun(int n)
{
cout<<cur<<" ";
visited[cur]=true;
q.push_back(cur);

do
{
for(int j=0;j<n;j++)
{
if(G[cur][j]==1 && !visited[j])
{
q.push_back(j);
cout<<j<<" ";
visited[j]=true;
}

}

q.pop_front();
if(!q.empty())
cur=q.front();
}while(!q.empty());
}```

Input Sequence:-

```9
0 1 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 0
0 0 0 1 1 1 0 0 1
0 0 1 0 0 0 0 0 0
0 0 1 0 0 0 0 1 0
0 0 1 0 0 0 1 0 0
0 0 0 0 0 1 0 1 1
0 0 0 0 1 0 1 0 0
1 0 1 0 0 0 1 0 0```

a) 2
b) 6
c) 8
d) 4

Explanation: The given code performs the breadth first search routine on the Graph.
The sequence obtained would be 0 1 8 2 6 3 4 5 7.

14 - Question

For which type of graph, the given program won’t run infinitely? The Input would be in the form of an adjacency Matrix and n is its dimension (1<n<10).

```#include <bits/stdc++.h>
using namespace std;
int G;
void fun(int n);

int main()
{
int num=0;
int n;
cin>>n;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
cin>>G[i][j];
fun(n);
return 0;
}

void fun(int n)
{
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(G[i][j]==1)
j--;
}```

a) All Fully Connected Graphs
b) All Empty Graphs
c) All Bipartite Graphs
d) All simple graphs

Explanation: For any graph (except empty graph) having edges, the condition G[i][j]==1 would hold true, which would result in an infinite loop.

15 - Question

Given the following adjacency matrix of a graph(G) determine the number of components in the G.

```[0 1 1 0 0 0],
[1 0 1 0 0 0],
[1 1 0 0 0 0],
[0 0 0 0 1 0],
[0 0 0 1 0 0],
[0 0 0 0 0 0].```

a) 1
b) 2
c) 3
d) 4