Dsa MCQS
Dsa MCQS
Dsa MCQS
Question 1:
Question 2:
a) Directed graph
b) Undirected graph
c) Cyclic graph
d) Weighted graph
Question 3:
Question 4:
Question 5:
Which of the following algorithms is used for traversing a graph in a systematic way?
a) Dijkstra's algorithm
b) Breadth-first search (BFS)
c) Depth-first search (DFS)
d) Prim's algorithm
Question 6:
What is the time complexity of depth-first search (DFS) in a graph with V vertices and E edges?
a) O(V)
b) O(E)
c) O(V + E)
d) O(log V)
Answer: c) O(V + E)
Question 7:
a) Dijkstra's algorithm
b) Topological sort
c) Kruskal's algorithm
d) Cycle detection algorithm
Question 8:
Question 9:
Question 10:
Which data structure is typically used to implement a priority queue in Dijkstra's algorithm?
a) Stack
b) Queue
c) Binary heap
d) Linked list
Question 11:
a) Dijkstra's algorithm
b) Bellman-Ford algorithm
c) Kruskal's algorithm
d) Prim's algorithm
Question 13:
a) n
b) n(n-1)/2
c) 2n
d) 2^(n-1)
Answer: b) n(n-1)/2
Question 14:
Which of the following is a popular algorithm for finding strongly connected components in a directed graph?
a) Dijkstra's algorithm
b) Kosaraju's algorithm
c) Floyd-Warshall algorithm
d) Johnson's algorithm
Question 16:
Question 17:
Which data structure is commonly used to implement depth-first search (DFS) in graph traversal?
a) Stack
b) Queue
c) Linked list
d) Priority queue
Answer: a) Stack
Quetion 18:
What is the time complexity of finding the shortest path using Bellman-Ford algorithm in a graph with V vertices and E edges?
a) O(V)
b) O(E)
c) O(V + E)
d) O(V * E)
Answer: c) O(V + E)
Question 19:
Question 20:
a) It has no vertices
b) It has no edges
c) It has no cycles
d) It has no weights
Question 21:
Question 22:
Which algorithm is suitable for finding the shortest path in a graph with positive edge weights?
a) Dijkstra's algorithm
b) Bellman-Ford algorithm
c) Prim's algorithm
d) Kruskal's algorithm
Question 23:
What is the minimum number of edges required to create a connected graph with n vertices?
a) n-1
b) n
c) n+1
d) 2n
Answer: a) n-1
Question 24:
In a topological sort of a directed acyclic graph (DAG), which vertex has no incoming edges?
a) Source vertex
b) Sink vertex
c) Cut vertex
d) Articulation point
Question 25:
Which of the following is a greedy algorithm used for finding the minimum spanning tree of a graph?
a) Dijkstra's algorithm
b) Bellman-Ford algorithm
c) Kruskal's algorithm
d) Floyd-Warshall algorithm
Question 26:
Question 27:
Question 28:
Answer: d) A graph whose vertices can be divided into two disjoint sets
Question 29:
Answer: d) They have a cycle that visits every edge exactly once
Question 30:
What is the time complexity of Kruskal's algorithm for finding the minimum spanning tree in a graph with V vertices and E
edges?
a) O(V)
b) O(E)
c) O(V log V)
d) O(E log E)
Question 2: Which type of graph does Dijkstra's algorithm work on? a) Directed acyclic graph b) Undirected graph c) Weighted graph
with non-negative edge weights d) Bipartite graph
Question 3: What is the main goal of Dijkstra's algorithm? a) Finding the longest path in a graph b) Finding the minimum spanning tree
c) Finding the most connected vertex d) Finding the shortest paths from a source vertex to all other vertices
Answer: d) Finding the shortest paths from a source vertex to all other vertices
Question 4: In Dijkstra's algorithm, how are the shortest distances initialized? a) All distances set to 1 b) The source distance set to 0,
others to ∞ c) Randomly assigned distances d) All distances set to ∞
Question 5: Which data structure is commonly used to implement the priority queue in Dijkstra's algorithm? a) Stack b) Queue c) Min-
heap d) Linked list
Answer: c) Min-heap
Question 6: What happens if a shorter path to a vertex is discovered in Dijkstra's algorithm? a) The longer path is retained b) The
shorter path is ignored c) The shorter path is updated d) The algorithm terminates
Question 8: What is the time complexity of Dijkstra's algorithm in the worst case? a) O(V) b) O(E) c) O(V + E) d) O(V log V)
Answer: c) O(V + E)
Question 9: What type of graphs can Dijkstra's algorithm handle efficiently? a) Directed graphs with cycles b) Undirected graphs with
negative weights c) Weighted graphs with negative weights d) Directed acyclic graphs
Question 10: What does Dijkstra's algorithm guarantee about the paths it finds? a) Longest paths b) Random paths c) Shortest paths d)
Paths with negative weights
Question 11: In Dijkstra's algorithm, what is the purpose of the predecessor array (p[v])? a) To store the vertex colors b) To store the
shortest distances c) To reconstruct the shortest paths d) To store the weights of edges
Question 12: What happens if a graph in Dijkstra's algorithm contains negative edge weights? a) The algorithm works correctly b) The
algorithm may produce incorrect results c) The algorithm terminates early d) The algorithm gives an error
a) Shortest Path
b) Minimum Spanning Tree
c) Sorting
d) Graph Traversal
a) Random node
b) Node with the highest degree
c) Node with the lowest degree
d) Node with the lowest weight
Question 3: Which of the following data structures is typically used to implement Prim's algorithm?
a) Stack
b) Queue
c) Priority Queue
d) Linked List
Question 4: In Prim's algorithm, what does the term "cut" refer to?
Question 5: What is the time complexity of Prim's algorithm using a binary heap priority queue for a graph with �V vertices and �E
edges?
a) O(V)
b) O(E)
c) O(V log V)
d) O(E log V)
Question 6: In Prim's algorithm, how is the next edge added to the minimum spanning tree?
a) Randomly
b) By selecting the edge with the lowest weight
c) By selecting the edge with the highest weight
d) By selecting the edge with the maximum degree
Question 7: What does the term "greedy" in Prim's algorithm refer to?
Question 9: Which property ensures that Prim's algorithm produces a correct minimum spanning tree?
a) Triangle Inequality
b) Cut Property
c) Euler's Formula
d) De Bruijn sequence
Question 10: If a graph has V vertices, the minimum number of edges needed to form a minimum spanning tree is:
a) V
b)V−1
c) 2V−2
d) 2V
Answer: b) V−1
Question 11: Which data structure is suitable for efficiently extracting the minimum-weight edge in each iteration of Prim's algorithm?
a) Stack
b) Queue
c) Priority Queue
d) Linked List
Answer: c) Priority Queue
Question 12: In Prim's algorithm, what happens if two edges have the same minimum weight?
Question 13: What is the main advantage of Prim's algorithm over Kruskal's algorithm?
a) Simplicity
b) Guaranteed correctness
c) Faster runtime
d) Applicability to disconnected graphs
Question 14: Which step is essential in the initialization phase of Prim's algorithm?
Question 15: What is the significance of the "Cut Property" in Prim's algorithm?
Question 16: Which of the following statements is true about Prim's algorithm?
Kruskul Algorithm
Question 1: What is Kruskal's algorithm used for?
a) Shortest Path
b) Minimum Spanning Tree
c) Sorting
d) Graph Traversal
a) Random node
b) Node with the highest degree
c) Node with the lowest degree
d) Node with the lowest weight
Question 3: Which of the following data structures is typically used to implement Kruskal's algorithm?
a) Stack
b) Queue
c) Priority Queue
d) Disjoint Set (Union-Find)
Question 4: In Kruskal's algorithm, what does the term "cut" refer to?
Question 5: What is the time complexity of Kruskal's algorithm using a disjoint set data structure for a graph with �V vertices and �E
edges?
a) O(V)
b) O(E)
c) O(E log V)
d) O(V log V)
Question 6: In Kruskal's algorithm, how is the next edge added to the minimum spanning tree?
a) Randomly
b) By selecting the edge with the lowest weight
c) By selecting the edge with the highest weight
d) By selecting the edge with the maximum degree
Question 7: What does the term "greedy" in Kruskal's algorithm refer to?
Question 9: Which property ensures that Kruskal's algorithm produces a correct minimum spanning tree?
a) Triangle Inequality
b) Cut Property
c) Euler's Formula
d) De Bruijn sequence
a) �V
b) �−1V−1
c) 2�−22V−2
d) 2�2V
Answer: b) �−1V−1
Question 11: Which data structure is suitable for efficiently checking whether adding an edge creates a cycle in Kruskal's algorithm?
a) Stack
b) Queue
c) Priority Queue
d) Disjoint Set (Union-Find)
Question 12: In Kruskal's algorithm, what happens if two edges have the same minimum weight?
Question 13: What is the main advantage of Kruskal's algorithm over Prim's algorithm?
a) Simplicity
b) Guaranteed correctness
c) Faster runtime
d) Applicability to disconnected graphs
Answer: d) Applicability to disconnected graphs
Question 14: Which step is essential in the initialization phase of Kruskal's algorithm?
Question 15: What is the significance of the "Cut Property" in Kruskal's algorithm?
Question 16: Which of the following statements is true about Kruskal's algorithm?
Question 19: In Kruskal's algorithm, what does the rank of a set represent?
Question 1: What is the time complexity of searching for an element in a balanced Binary Search Tree (BST)? a) O(1) b) O(log n) c) O(n)
d) O(n log n)
Answer: b) O(log n)
Question 2: In a Binary Search Tree (BST), what is the time complexity of inserting a new element? a) O(1) b) O(log n) c) O(n) d) O(n log
n)
Answer: b) O(log n)
Question 3: In a Binary Search Tree (BST), what is the time complexity of deleting a node with two children? a) O(1) b) O(log n) c) O(n)
d) O(n log n)
Answer: b) O(log n)
Question 4: What is the primary advantage of using a Self-Balancing Binary Search Tree (e.g., AVL tree) over a regular BST? a) Simplicity
b) Faster search operations c) Efficient memory usage d) Maintains balance, ensuring O(log n) height
Question 5: In a Binary Search Tree (BST), what is the maximum number of comparisons needed to search for an element? a) Height of
the tree b) Twice the height of the tree c) Logarithm of the number of nodes d) The number of nodes in the tree
AVL Trees:
Question 6: What is the minimum height of an AVL tree with n nodes? a) log n b) n/2 c) log(n+1) - 1 d) n
Answer: a) log n
Question 7: In an AVL tree, what is the time complexity of finding the minimum element? a) O(1) b) O(log n) c) O(n) d) O(n log n)
Answer: b) O(log n)
Question 8: In AVL trees, rotations are performed to maintain: a) Maximum height b) Minimum height c) Binary search property d)
Balance property
Question 9: In AVL trees, which rotation is performed to balance the tree when a left child has a right child? a) Left-Left rotation b)
Right-Right rotation c) Left-Right rotation d) Right-Left rotation
Question 10: The AVL tree is named after its inventors Adelson-Velsky and Landis. a) True b) False
Answer: a) True
Question 11: In a complete binary tree, the last level is filled from: a) Left to right b) Right to left c) Randomly d) Center to outward
Question 13: In a complete binary tree, what is the index of the parent of a node at index i? a) 2i b) i/2 c) i+1 d) 2i+1
Answer: b) i/2
Question 14: The height of a complete binary tree with n nodes is: a) O(n) b) O(log n) c) O(n log n) d) O(1)
Answer: b) O(log n)
Question 15: In a complete binary tree, what is the maximum number of nodes at level k? a) 2^k b) 2^(k+1) - 1 c) k d) k^2
Answer: a) 2^k
2. 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)
View Answer
Ans : C
Explanation: Out of n*n possible values for a simple graph the diagonal values will always be zero.
3. Which of the following is an advantage of adjacency list representation over adjacency matrix representation
of a graph?
A. In adjacency list representation, space is saved for sparse graphs.
B. DFS and BSF can be done in O(V + E) time for adjacency list representation. These operations take O(V^2) time in
adjacency matrix representation. Here is V and E are number of vertices and edges respectively.
C. Adding a vertex in adjacency list representation is easier than adjacency matrix representation.
D. All of the above
View Answer
Ans : D
Explanation: No explanation.
4.A connected planar graph having 6 vertices, 7 edges contains _____________ regions.
A. 15
B. 3
C. 1
D. 11
View Answer
Ans : B
Explanation: By euler’s formula the relation between vertices(n), edges(q) and regions(r) is given by n-q+r=2.
5.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
View Answer
Ans : C
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.
6. The degree sequence of a simple graph is the sequence of the degrees of the nodes in the graph in decreasing
order. Which of the following sequences can not be the degree sequence of any graph?
I. 7, 6, 5, 4, 4, 3, 2, 1
II. 6, 6, 6, 6, 3, 3, 2, 2
III. 7, 6, 6, 4, 4, 3, 2, 2
IV. 8, 7, 7, 6, 4, 2, 1, 1
A. I and II
B. III and IV
C. IV only
D. II and IV
View Answer
Ans : D
Explanation: No explanation
9.The most efficient algorithm for finding the number of connected components in an undirected graph on n
vertices and m edges has time complexity.
(A) \theta(n)
(B) \theta(m)
(C) \theta(m + n)
(D) \theta(mn)
A. A
B. B
C. C
D. D
View Answer
Ans : C
Explanation: Connected components can be found in O(m + n) using Tarjan's algorithm. Once we have connected components, we can
count them.
10. What is time complexity to check if a string(length S1) is a substring of another string(length S2) stored in a
Directed Acyclic Word Graph, given S2 is greater than S1?
A. O(S1)
B. O(S2)
C. O(S1+S2)
D. O(1)
View Answer
Ans : A
Explanation:For each check of a word of length S1, we need to follow at most S1 edges.
11. What is the number of edges present in a complete graph having n vertices?
A. (n*(n+1))/2
B. (n*(n-1))/2
C. n
D. Information given is insufficient
View Answer
Ans : B
Explanation: Number of ways in which every vertex can be connected to each other is nC2.
12. In a simple graph, the number of edges is equal to twice the sum of the degrees of the vertices.
A. True
B. False
View Answer
Ans : B
Explanation: The sum of the degrees of the vertices is equal to twice the number of edges.
13. If a simple graph G, contains n vertices and m edges, the number of edges in the Graph G'(Complement of G)
is ___________
A. (n*n-n-2*m)/2
B. (n*n+n+2*m)/2
C. (n*n-n-2*m)/2
D. (n*n-n+2*m)/2
View Answer
Ans : A
Explanation: The union of G and G’ would be a complete graph so, the number of edges in G’= number of edges in the complete form of
G(nC2)-edges in G(m).
14. Which of the following properties does a simple graph not hold?
A. Must be connected
B. Must be unweighted
C. Must have no loops or multiple edges
D. All of the mentioned
View Answer
Ans : A
Explanation: A simple graph maybe connected or disconnected.
16. For a given graph G having v vertices and e edges which is connected and has no cycles, which of the
following statements is true?
A. v=e
B. v = e+1
C. v + 1 = e
D. None of the mentioned
View Answer
Ans : B
Explanation: For any connected graph with no cycles the equation holds true.
17. for which of the following combinations of the degrees of vertices would the connected graph be eulerian?
A. 1,2,3
B. 2,3,4
C. 2,4,5
D. 1,3,5
View Answer
Ans : A
Explanation: A graph is eulerian if either all of its vertices are even or if only two of its vertices are odd.
18. A graph with all vertices having equal degree is known as a __________
A. Multi Graph
B. Regular Graph
C. Simple Graph
D. Complete Graph
View Answer
Ans : B
Explanation: The given statement is the definition of regular graphs.Explanation: The given statement is the definition of regular graphs.
Explanation: The 3 listed methods can be used, the choice depends on the ease of use.
20. 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)
View Answer
Ans : D