0% found this document useful (0 votes)
12 views

ADS unit-3,4 MCQs

The document contains multiple-choice questions (MCQs) related to graphs, algorithms, dynamic programming, and complexity classes such as P and NP. Each question is accompanied by the correct answer, covering topics like Depth-First Search, Dijkstra's Algorithm, dynamic programming characteristics, and approximation algorithms. It serves as a study guide for understanding key concepts in computer science.

Uploaded by

Tech Coder
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

ADS unit-3,4 MCQs

The document contains multiple-choice questions (MCQs) related to graphs, algorithms, dynamic programming, and complexity classes such as P and NP. Each question is accompanied by the correct answer, covering topics like Depth-First Search, Dijkstra's Algorithm, dynamic programming characteristics, and approximation algorithms. It serves as a study guide for understanding key concepts in computer science.

Uploaded by

Tech Coder
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Here are some multiple-choice questions (MCQs) related to graphs and algorithms:

1. What is the time complexity of Depth-First Search (DFS) in an adjacency


matrix representation of a graph?

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

Answer: A) Dijkstra’s Algorithm

3. In a directed graph, which of the following algorithms is used to detect a cycle?

A) Breadth-First Search
B) Depth-First Search
C) Dijkstra’s Algorithm
D) Kruskal’s Algorithm

Answer: B) Depth-First Search

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

5. In Prim's Minimum Spanning Tree (MST) algorithm, the time complexity


using a binary heap is:

A) O(V^2)
B) O(V log V + E log V)
C) O(E + V)
D) O(V^3)

Answer: B) O(V log V + E log V)

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

Answer: C) Breadth-First Search

9. Which of the following data structures can be used to implement a graph?

A) Linked List
B) Hash Table
C) Adjacency Matrix
D) Both B and C

Answer: 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)

Answer: A) O(E log V)

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

Answer: B) Bellman-Ford Algorithm

12. What does the adjacency list representation of a graph store?


A) A list of all the edges in the graph
B) A list of all vertices and their adjacent vertices
C) A matrix of vertices and edges
D) A tree structure of vertices

Answer: B) A list of all vertices and their adjacent vertices

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

Answer: 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

Answer: C) Kosaraju’s Algorithm


16. What is the primary difference between a directed graph and an undirected
graph?

A) A directed graph has edges with no direction.


B) An undirected graph has edges with direction.
C) A directed graph has edges that point in a specific direction.
D) There is no difference between them.

Answer: C) A directed graph has edges that point in a specific direction.

17. Which of the following is true for a tree?

A) It is a connected acyclic graph.


B) It is a graph with cycles.
C) It must have at least one cycle.
D) It is always disconnected.

Answer: A) It is a connected acyclic graph.

18. Which of the following statements about a topological sort of a directed graph
is true?

A) It is only possible in a connected graph.


B) It can be performed only on acyclic graphs.
C) It can be performed on any directed graph.
D) It is always a unique ordering of vertices.

Answer: B) It can be performed only on acyclic graphs.

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

Answer: D) A simple edge


20. Which of the following algorithms is used for finding the minimum spanning
tree of a graph?

A) Dijkstra’s Algorithm
B) Kruskal’s Algorithm
C) Bellman-Ford Algorithm
D) Floyd-Warshall Algorithm

Answer: B) Kruskal’s Algorithm

Here are some multiple-choice questions (MCQs) on dynamic programming, P, NP, and
approximation algorithms:

Dynamic Programming

1. Which of the following is a key characteristic of dynamic programming?

A) It solves problems by dividing them into smaller sub-problems that overlap.


B) It solves problems by using greedy methods.
C) It solves problems without using recursion.
D) It solves problems by solving them in a top-down manner.

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)

3. In dynamic programming, what is the purpose of memoization?

A) To store the solution to sub-problems to avoid recalculating them.


B) To solve the problem recursively.
C) To divide the problem into smaller problems.
D) To use a greedy approach for solving the problem.

Answer: A) To store the solution to sub-problems to avoid recalculating them.


4. Which of the following problems can be solved using dynamic programming?

A) Maximum Subarray Problem


B) Knapsack Problem
C) Longest Common Subsequence
D) All of the above

Answer: D) All of the above

5. The Bellman-Ford algorithm is an example of:

A) Divide and conquer


B) Greedy algorithm
C) Dynamic programming
D) Backtracking

Answer: C) Dynamic programming

P, NP, and Approximation

6. Which of the following statements about P and NP is true?

A) P problems can be solved in polynomial time.


B) NP problems can be solved in non-polynomial time.
C) If a problem is NP-complete, it is also in P.
D) P = NP is proven to be true.

Answer: A) P problems can be solved in polynomial time.

7. Which of the following is true about NP-hard problems?

A) They can always be solved in polynomial time.


B) They are a subset of NP problems.
C) An NP-hard problem is at least as hard as the hardest NP problem.
D) NP-hard problems can always be approximated in polynomial time.

Answer: C) An NP-hard problem is at least as hard as the hardest NP problem.


8. Which of the following problems is known to be NP-complete?

A) Travelling Salesman Problem (TSP)


B) Sorting a list of numbers
C) Finding the shortest path in a graph
D) Matrix multiplication

Answer: A) Travelling Salesman Problem (TSP)

9. The class NP contains problems that:

A) Can be solved in polynomial time.


B) Can be verified in polynomial time, but not necessarily solved in polynomial time.
C) Can be solved in logarithmic time.
D) Cannot be verified in polynomial time.

Answer: B) Can be verified in polynomial time, but not necessarily solved in polynomial
time.

10. If P = NP, what would that imply about NP-complete problems?

A) They can be solved in polynomial time.


B) They can be solved in exponential time.
C) They are impossible to solve.
D) They can be approximated in polynomial time.

Answer: A) They can be solved in polynomial time.

11. What does the approximation algorithm for a problem aim to do?

A) Find an exact solution to the problem.


B) Find a solution that is within a specified factor of the optimal solution.
C) Find a solution that is worse than the optimal solution.
D) Solve the problem faster than the optimal algorithm.

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)?

A) Dynamic Programming approach


B) Greedy algorithm
C) Christofides' algorithm
D) Dijkstra’s algorithm

Answer: C) Christofides' algorithm

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?

A) Sorting a list of numbers


B) Integer Factorization
C) Travelling Salesman Problem
D) Knapsack Problem

Answer: B) Integer Factorization

15. The "greedy" approach to solving an optimization problem is often used in:

A) Dynamic programming algorithms


B) Approximation algorithms
C) Divide and conquer algorithms
D) Backtracking algorithms

Answer: B) Approximation algorithms


16. What is the main difference between NP-complete and NP-hard problems?

A) NP-complete problems can be solved in polynomial time, NP-hard problems cannot.


B) NP-complete problems are easier than NP-hard problems.
C) NP-hard problems are at least as hard as NP-complete problems, but they may not be in NP.
D) There is no difference between them.

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?

A) They always find the exact optimal solution.


B) Exact solutions are computationally impractical for large inputs, but approximate solutions
can be found quickly.
C) They provide exact solutions without any approximation.
D) They make NP problems easier to solve.

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

19. Which of the following is an example of a greedy algorithm?

A) Knapsack Problem (Dynamic Programming version)


B) Prim’s Algorithm for Minimum Spanning Tree
C) Dijkstra’s Algorithm for Shortest Path
D) Both B and C
Answer: D) Both B and C

20. In the context of approximation algorithms, a solution is said to be within an


approximation factor of k if:

A) The algorithm guarantees to find the optimal solution.


B) The solution is always at most k times worse than the optimal solution.
C) The solution is always at least k times worse than the optimal solution.
D) The solution is always exactly k times better than the optimal solution.

Answer: B) The solution is always at most k times worse than the optimal solution.

You might also like