Grade – 12 – Computer Science – Computational Complexity and Algorithms – Multiple Choice Questions

Multiple Choice Questions

Computational Complexity and Algorithms

Topic: Computational Complexity and Algorithms
Grade: 12

Question 1:
Which of the following complexity classes represents the highest level of computational complexity?
a) P
b) NP
c) NP-complete
d) NP-hard

Answer: d) NP-hard
Explanation: NP-hard is a class of problems that are at least as hard as the hardest problems in the class NP. This means that any problem in NP can be reduced to an NP-hard problem in polynomial time. An example of an NP-hard problem is the traveling salesman problem, where the goal is to find the shortest possible route that visits a given set of cities and returns to the starting city.

Question 2:
Which of the following is an example of an NP-complete problem?
a) Sorting a list of integers in ascending order
b) Finding the maximum element in an array
c) Determining whether a graph is connected
d) Solving the traveling salesman problem

Answer: d) Solving the traveling salesman problem
Explanation: NP-complete problems are a subset of NP problems that are both in NP and NP-hard. These are the most difficult problems in NP and have the property that if one NP-complete problem can be solved in polynomial time, then all NP problems can be solved in polynomial time. The traveling salesman problem is an example of an NP-complete problem, where the goal is to find the shortest possible route that visits a given set of cities and returns to the starting city.

Question 3:
Which of the following best describes the time complexity of an algorithm that runs in O(n^2)?
a) Quadratic time complexity
b) Linear time complexity
c) Exponential time complexity
d) Logarithmic time complexity

Answer: a) Quadratic time complexity
Explanation: An algorithm with a time complexity of O(n^2) has a quadratic time complexity. This means that the running time of the algorithm increases proportionally to the square of the input size. For example, a nested loop that iterates over an array of size n would have a time complexity of O(n^2).

Question 4:
Which of the following best describes the space complexity of an algorithm that uses O(n) extra space?
a) Constant space complexity
b) Linear space complexity
c) Exponential space complexity
d) Logarithmic space complexity

Answer: b) Linear space complexity
Explanation: An algorithm with a space complexity of O(n) uses a linear amount of extra space. This means that the amount of extra space required by the algorithm increases proportionally to the input size. For example, an algorithm that creates a new array of size n to store the result would have a space complexity of O(n).

Question 5:
Which of the following best describes the worst-case time complexity of an algorithm that runs in O(log n)?
a) Quadratic time complexity
b) Linear time complexity
c) Logarithmic time complexity
d) Exponential time complexity

Answer: c) Logarithmic time complexity
Explanation: An algorithm with a time complexity of O(log n) has a logarithmic time complexity. This means that the running time of the algorithm increases logarithmically with the input size. For example, a binary search algorithm has a time complexity of O(log n) as it divides the search space in half at each step.

Question 6:
Which of the following is true about the class P?
a) P contains all problems that can be solved in polynomial time
b) P contains all problems that can be solved in exponential time
c) P contains all problems that are solvable
d) P contains all problems that are unsolvable

Answer: a) P contains all problems that can be solved in polynomial time
Explanation: The class P contains all problems that can be solved in polynomial time. This means that there exists an algorithm that can solve the problem with a running time that is a polynomial function of the input size. For example, sorting a list of integers in ascending order can be solved in O(n log n) time, which is a polynomial time complexity.

Question 7:
Which of the following is true about the class NP?
a) NP contains all problems that can be solved in polynomial time
b) NP contains all problems that can be solved in exponential time
c) NP contains all problems that are solvable
d) NP contains all problems that are unsolvable

Answer: b) NP contains all problems that can be solved in exponential time
Explanation: The class NP contains all problems for which a potential solution can be verified in polynomial time. This means that given a potential solution, there exists an algorithm that can determine whether the solution is correct or not in polynomial time. However, finding the solution itself may require exponential time. For example, the subset sum problem is in NP, as it can be verified in polynomial time, but finding the solution may require checking all possible subsets, which takes exponential time.

Question 8:
Which of the following is true about the class NP-complete?
a) NP-complete contains all problems that can be solved in polynomial time
b) NP-complete contains all problems that can be solved in exponential time
c) NP-complete contains all problems that are solvable
d) NP-complete contains all problems that are unsolvable

Answer: b) NP-complete contains all problems that can be solved in exponential time
Explanation: The class NP-complete contains all problems in NP that are as hard as the hardest problems in NP. This means that any problem in NP can be reduced to an NP-complete problem in polynomial time. The solution to an NP-complete problem itself may require exponential time. For example, the traveling salesman problem is NP-complete, as any problem in NP can be reduced to it and finding the solution requires checking all possible routes, which takes exponential time.

Question 9:
Which of the following is true about the class NP-hard?
a) NP-hard contains all problems that can be solved in polynomial time
b) NP-hard contains all problems that can be solved in exponential time
c) NP-hard contains all problems that are solvable
d) NP-hard contains all problems that are unsolvable

Answer: d) NP-hard contains all problems that are unsolvable
Explanation: The class NP-hard contains all problems that are at least as hard as the hardest problems in NP. This means that any problem in NP can be reduced to an NP-hard problem in polynomial time. NP-hard problems may or may not be solvable. For example, the halting problem is NP-hard, as any problem in NP can be reduced to it, but it is unsolvable as there is no algorithm that can determine whether an arbitrary program halts or not.

Question 10:
Which of the following best describes the time complexity of an algorithm that runs in O(1)?
a) Quadratic time complexity
b) Linear time complexity
c) Constant time complexity
d) Exponential time complexity

Answer: c) Constant time complexity
Explanation: An algorithm with a time complexity of O(1) has a constant time complexity. This means that the running time of the algorithm is independent of the input size. For example, accessing an element in an array by its index has a time complexity of O(1), as it takes the same amount of time regardless of the size of the array.

Question 11:
Which of the following best describes the space complexity of an algorithm that uses O(1) extra space?
a) Constant space complexity
b) Linear space complexity
c) Exponential space complexity
d) Logarithmic space complexity

Answer: a) Constant space complexity
Explanation: An algorithm with a space complexity of O(1) uses a constant amount of extra space. This means that the amount of extra space required by the algorithm is fixed and does not depend on the input size. For example, swapping two variables using a temporary variable has a space complexity of O(1), as it only requires a fixed amount of extra space.

Question 12:
Which of the following best describes the worst-case time complexity of an algorithm that runs in O(n)?
a) Quadratic time complexity
b) Linear time complexity
c) Logarithmic time complexity
d) Exponential time complexity

Answer: b) Linear time complexity
Explanation: An algorithm with a time complexity of O(n) has a linear time complexity. This means that the running time of the algorithm increases proportionally to the input size. For example, iterating over an array of size n has a time complexity of O(n), as it takes n operations to visit each element in the array.

Question 13:
Which of the following best describes the space complexity of an algorithm that uses O(log n) extra space?
a) Constant space complexity
b) Linear space complexity
c) Exponential space complexity
d) Logarithmic space complexity

Answer: d) Logarithmic space complexity
Explanation: An algorithm with a space complexity of O(log n) uses a logarithmic amount of extra space. This means that the amount of extra space required by the algorithm increases logarithmically with the input size. For example, a binary search algorithm that uses a recursive implementation has a space complexity of O(log n), as the maximum depth of the recursion is logarithmic in the input size.

Question 14:
Which of the following complexity classes represents the lowest level of computational complexity?
a) P
b) NP
c) NP-complete
d) NP-hard

Answer: a) P
Explanation: P is the class of problems that can be solved in polynomial time. These are the problems that can be solved efficiently, as the running time of the algorithm is bounded by a polynomial function of the input size. For example, sorting a list of integers in ascending order can be solved in O(n log n) time, which is a polynomial time complexity.

Question 15:
Which of the following is an example of an NP problem that is not known to be in P?
a) Sorting a list of integers in ascending order
b) Finding the maximum element in an array
c) Determining whether a graph is connected
d) Solving the traveling salesman problem

Answer: d) Solving the traveling salesman problem
Explanation: The traveling salesman problem is an example of an NP problem that is not known to be in P. It is a difficult problem that involves finding the shortest possible route that visits a given set of cities and returns to the starting city. Although there are algorithms that can solve the problem with exponential time complexity, it is not known whether there exists a polynomial time algorithm for solving it.

Leave a Comment

Your email address will not be published. Required fields are marked *

Shopping Cart
error: Content cannot be copied. it is protected !!
Scroll to Top