ADS unit-3,4 MCQs
ADS unit-3,4 MCQs
A) O(V + E)
B) O(V^2)
C) O(V)
D) O(E)
Answer: B) O(V^2)
2. Which of the following is the most efficient algorithm to find the shortest path
in a graph with non-negative weights?
A) Dijkstra’s Algorithm
B) Bellman-Ford Algorithm
C) Floyd-Warshall Algorithm
D) A* Algorithm
A) Breadth-First Search
B) Depth-First Search
C) Dijkstra’s Algorithm
D) Kruskal’s Algorithm
4. Which of the following graph traversal methods uses a queue for storing
nodes?
A) Depth-First Search
B) Prim’s Algorithm
C) Breadth-First Search
D) Kruskal’s Algorithm
Answer: C) Breadth-First Search
A) O(V^2)
B) O(V log V + E log V)
C) O(E + V)
D) O(V^3)
6. What is the space complexity of Depth-First Search (DFS) in the worst case?
A) O(V)
B) O(E)
C) O(V + E)
D) O(V^2)
Answer: A) O(V)
7. In a graph with VVV vertices and EEE edges, what is the worst-case time
complexity of performing BFS?
A) O(V^2)
B) O(E + V)
C) O(V^2 + E)
D) O(E)
Answer: B) O(E + V)
8. Which of the following algorithms is best suited for finding the shortest path in
a graph where all edge weights are equal?
A) Dijkstra’s Algorithm
B) Bellman-Ford Algorithm
C) Breadth-First Search
D) Floyd-Warshall Algorithm
A) Linked List
B) Hash Table
C) Adjacency Matrix
D) Both B and C
10. What is the time complexity of finding the Minimum Spanning Tree using
Kruskal’s algorithm?
A) O(E log V)
B) O(V log E)
C) O(V^2)
D) O(E^2)
11. Which of the following algorithms can be used to find the shortest path from
a single source to all other vertices in a graph with negative weights (but no
negative-weight cycles)?
A) Dijkstra’s Algorithm
B) Bellman-Ford Algorithm
C) Floyd-Warshall Algorithm
D) A* Algorithm
13. Which of the following is NOT a valid method for detecting cycles in an
undirected graph?
A) Union-Find Algorithm
B) Depth-First Search
C) Breadth-First Search
D) Floyd-Warshall Algorithm
14. In an undirected graph, how many edges are there in a complete graph with
nnn vertices?
A) n(n−1)2\frac{n(n-1)}{2}2n(n−1)
B) n(n−1)n(n-1)n(n−1)
C) n2n^2n2
D) n(n+1)n(n+1)n(n+1)
Answer: A) n(n−1)2\frac{n(n-1)}{2}2n(n−1)
15. Which of the following algorithms is used for finding the strongly connected
components in a directed graph?
A) Kruskal’s Algorithm
B) Bellman-Ford Algorithm
C) Kosaraju’s Algorithm
D) Prim’s Algorithm
18. Which of the following statements about a topological sort of a directed graph
is true?
19. In a graph, if two vertices are connected by an edge, then the edge is called:
A) A directed edge
B) A weighted edge
C) A loop
D) A simple edge
A) Dijkstra’s Algorithm
B) Kruskal’s Algorithm
C) Bellman-Ford Algorithm
D) Floyd-Warshall Algorithm
Here are some multiple-choice questions (MCQs) on dynamic programming, P, NP, and
approximation algorithms:
Dynamic Programming
Answer: A) It solves problems by dividing them into smaller sub-problems that overlap.
2. The time complexity of the Fibonacci sequence using dynamic programming is:
A) O(2^n)
B) O(n^2)
C) O(n)
D) O(n log n)
Answer: C) O(n)
Answer: B) Can be verified in polynomial time, but not necessarily solved in polynomial
time.
11. What does the approximation algorithm for a problem aim to do?
Answer: B) Find a solution that is within a specified factor of the optimal solution.
12. Which of the following is a commonly used approximation algorithm for the Travelling
Salesman Problem (TSP)?
13. What is the time complexity of solving the Knapsack problem using dynamic
programming?
A) O(n * W)
B) O(n^2)
C) O(n * log W)
D) O(2^n)
Answer: A) O(n * W)
Where n is the number of items and W is the capacity of the knapsack.
14. Which of the following is an example of a problem in NP that is not known to be NP-
complete?
15. The "greedy" approach to solving an optimization problem is often used in:
Answer: C) NP-hard problems are at least as hard as NP-complete problems, but they may
not be in NP.
17. Which of the following is a valid reason why approximation algorithms are important for
NP-hard problems?
Answer: B) Exact solutions are computationally impractical for large inputs, but
approximate solutions can be found quickly.
18. Which of the following is a common approximation ratio for the Travelling Salesman
Problem using the Christofides’ algorithm?
A) 1
B) 2
C) 1.5
D) 3
Answer: C) 1.5
Answer: B) The solution is always at most k times worse than the optimal solution.