Data Structures Algorithms - Quiz(MCQ)
A)
int a[3] = {1, 2, 3};
B)
int a = {1, 2, 3};
C)
int a(3) = [1, 2, 3];
D)
int a[] = new int[3]

Correct Answer : Option (A) :   int a[3] = {1, 2, 3};

A)
Array
B)
Graphs
C)
AVL Trees
D)
Binary Trees

Correct Answer : Option (A) :   Array

A)
List
B)
Array
C)
Stack
D)
Queue

Correct Answer : Option (C) :   Stack

A)
O(n)
B)
O(n^2)
C)
O(n^4)
D)
O(n^3)

Correct Answer : Option (D) :   O(n^3)

5 .
What does the following code snippet do?
``````void dfs(int node, vector<vector<int>> &edges, vector<bool> &vis, vector<int> &dp) {
vis[node] = true;
for(auto x: edges[node]) {
if(!vis[x]) {
dp[x] = dp[node] + 1;
dfs(x, edges, vis, dp);
}
}
}``````
A)
Finds the diameter of a tree.
B)
Counts the number of nodes in a given tree.
C)
Checks if all the nodes are reachable in a given tree.
D)
Stores depths of all the nodes in a given tree, with respect to some root node.

Correct Answer : Option (D) :   Stores depths of all the nodes in a given tree, with respect to some root node.

A)
Path
B)
Centroid
C)
Center
D)
Diameter

Correct Answer : Option (B) :   Centroid

7 .
What does the following code snippet calculate (edges represent the adjacency list representation of a graph)?
``````void solve(vector<vector<int>> edges) {
int count = 0;
for(auto x: edges) {
for(auto y: x) {
count += 1;
}
}
cout << count / 2 << endl;
}``````
A)
Calculates the number of nodes in a given graph.
B)
Calculates the sum of degrees of all nodes in a given graph.
C)
Calculates the number of edges in an undirected graph.
D)
None of the above.

Correct Answer : Option (C) :   Calculates the number of edges in an undirected graph.

A)
Left -> Right -> Root
B)
Left -> Root -> Right
C)
Right -> Left -> Root
D)
Right -> Root -> Left

Correct Answer : Option (A) :   Left -> Right -> Root

A)
The value of the current node
B)
The address of the next node if it exists
C)
Both (A) and (B)
D)
None of the above

Correct Answer : Option (C) :   Both (A) and (B)

A)
*(a + 2)
B)
*a + 2
C)
&(a + 2)
D)
*(*a + 2)

Correct Answer : Option (A) :   *(a + 2)