Chapter9 Nokey
Chapter9 Nokey
44.
What is the maximum number of children a node can have in an n-ary tree?
2
0
1
n
...
45.
Worst case time complexity to access an element in a BST can be?
O(n)
O(n * logn)
O(1)
O(logn)
...
46.
Which of the following represents the Postorder Traversal of a Binary Tree?
Left -> Right -> Root
Left -> Root -> Right
Right -> Left -> Root
Right -> Root -> Left
...
47.
In what time complexity can we find the diameter of a binary tree optimally?
O(V + E)
O(V)
O(E)
O(V * logE)
...
48.
Which of the following statements is true about AVL Trees?
The difference between the heights of left and right nodes cannot be more than 1.
The height of an AVL Tree always remains of the order of O(logn)
AVL Trees are a type of self-balancing Binary Search Trees.
All of the above.
...
49.
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;
}
Calculates the number of edges in an undirected graph.
Calculates the number of nodes in a given graph.
Calculates the sum of degrees of all nodes in a given graph.
None of the above.
...
50.
In a graph of n nodes and n edges, how many cycles will be present?
Exactly 1
At most 1
At most 2
Depends on the graph
...
51.
A node in a tree, such that removing it splits the tree into forests, with size of each
connected component being not greater than n / 2 is called?
Center
Diameter
Centroid
Path
...
52.
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);
}
}
}
Stores depths of all the nodes in a given tree, with respect to some root node.
Counts the number of nodes in a given tree.
Finds the diameter of a tree.
Checks if all the nodes are reachable in a given tree.
...
53.
Which of the following algorithms are used to find the shortest path from a source node
to all other nodes in a weighted graph?
BFS.
Djikstra’s Algorithm.
Prims Algorithm.
Kruskal’s Algorithm.
...
54.
What is the best time complexity we can achieve to precompute all-pairs shortest paths
in a weighted graph?
O(n^3)
O(n^2)
O(n)
O(n^4)
...
55.
Which data structure is mainly used for implementing the recursive algorithm?
Queue
Stack
Array
List
...