Each question below shows the correct answer with a full explanation. Use these to build conceptual understanding before attempting a timed quiz.
Complexity & OptimizationEasy
Q1. Which is more efficient: O(n) or O(n log n)?
- A.Depends on constants
- B.O(n) is more efficient✓ Correct
- C.O(n log n) is better
- D.They are equivalent
Explanation
O(n) is more efficient than O(n log n) because n grows slower than n log n for large values of n.
Report an error in this question
Complexity & OptimizationEasy
Q2. Which is faster: O(log n) or O(√n)?
- A.They are equivalent
- B.O(log n) is faster✓ Correct
- C.O(√n) is faster
- D.Cannot compare them
Explanation
O(log n) grows slower than O(√n) for large n. For example, when n = 1,000,000: log n ≈ 20 while √n = 1,000.
Report an error in this question
Complexity & OptimizationMedium
Q3. What is an NP-complete problem?
- A.A problem that cannot be solved at all
- B.A problem with no known algorithm existing
- C.A problem in NP as hard as any NP problem✓ Correct
- D.A problem that runs in constant time always
Explanation
An NP-complete problem is in NP and is as hard as any NP problem: every problem in NP can be reduced to it in polynomial time.
Report an error in this question
Complexity & OptimizationEasy
Q4. What is the time complexity of finding the maximum element in an unsorted array?
- A.O(n)✓ Correct
- B.O(n^2)
- C.O(1)
- D.O(log n)
Explanation
Finding the maximum in an unsorted array requires examining every element, taking O(n) time.
Report an error in this question
Complexity & OptimizationMedium
Q5. What is the relationship between P and NP?
- A.P and NP are completely disjoint sets
- B.P = NP has been proven true conclusively
- C.NP ⊆ P has been proven true conclusively
- D.P ⊆ NP, but whether P = NP is open✓ Correct
Explanation
Every problem in P is also in NP (P ⊆ NP). Whether P = NP (every NP problem has a polynomial solution) is one of the most important open problems in computer science.
Report an error in this question
Complexity & OptimizationMedium
Q6. What is an NP-hard problem?
- A.A problem with a known polynomial time solution
- B.A problem that is always in the class P
- C.A problem that is easy to solve efficiently
- D.A problem at least as hard as NP-complete problems✓ Correct
Explanation
An NP-hard problem is at least as hard as NP-complete problems. It may or may not be in NP (its solution may not be verifiable in polynomial time).
Report an error in this question
Complexity & OptimizationEasy
Q7. What is the significance of O(n!) complexity?
- A.It is essentially the same as O(n^2) complexity class
- B.It is classified as a polynomial time complexity class
- C.It is very efficient for all possible input sizes given
- D.It is extremely inefficient, growing super-exponentially✓ Correct
Explanation
O(n!) (factorial) is one of the fastest-growing complexities, making algorithms with this complexity practical only for very small inputs.
Report an error in this question
Complexity & OptimizationEasy
Q8. What does NP stand for in computational complexity?
- A.New computational Problems class
- B.Non-deterministic Polynomial time✓ Correct
- C.Not Polynomial time class
- D.No Proof available for it
Explanation
NP stands for Non-deterministic Polynomial time: problems whose solutions can be verified in polynomial time by a deterministic Turing machine.
Report an error in this question
Complexity & OptimizationEasy
Q9. What is time-space tradeoff?
- A.Time complexity cannot affect space complexity
- B.Time and space are always equal in measure
- C.Using more time to save space or vice versa✓ Correct
- D.A method to reduce both time and space simultaneously
Explanation
A time-space tradeoff means that an algorithm can use more memory to run faster, or use less memory at the cost of running slower.
Report an error in this question
Complexity & OptimizationEasy
Q10. What is the best time complexity achievable for comparison-based sorting?
- A.O(log n)
- B.O(n log n)✓ Correct
- C.O(n)
- D.O(n^2)
Explanation
The lower bound for any comparison-based sorting algorithm is Ω(n log n), proven using the decision tree model.
Report an error in this question
Complexity & OptimizationEasy
Q11. What does 'in-place algorithm' mean?
- A.An algorithm that runs at a specific location
- B.An algorithm using only constant extra space✓ Correct
- C.An algorithm that cannot be relocated in memory
- D.An algorithm that only sorts data in place
Explanation
An in-place algorithm uses only O(1) or O(log n) extra space beyond the input, modifying the input directly rather than using auxiliary data structures.
Report an error in this question
Complexity & OptimizationEasy
Q12. What does P stand for in computational complexity?
- A.Problems solvable in polynomial time✓ Correct
- B.Prime number problems class
- C.Probability problems class
- D.Parallel problems class
Explanation
P is the class of decision problems that can be solved by a deterministic Turing machine in polynomial time.
Report an error in this question
Complexity & OptimizationEasy
Q13. What is the time complexity of accessing an element in a hash table on average?
- A.O(n^2)
- B.O(log n)
- C.O(1)✓ Correct
- D.O(n)
Explanation
Hash tables provide O(1) average-case time for access, insertion, and deletion with a good hash function.
Report an error in this question
Complexity & OptimizationMedium
Q14. What is memoization's space-time tradeoff?
- A.It uses no extra space at all
- B.It uses extra space to avoid redundant computation✓ Correct
- C.It increases time to save storage space
- D.It reduces both space and time simultaneously
Explanation
Memoization trades extra memory (to store computed results) for faster execution (by looking up previously computed results instead of recomputing them).
Report an error in this question
Complexity & OptimizationHard
Q15. What is the complexity class PSPACE?
- A.Problems solvable using polynomial space amount✓ Correct
- B.Problems requiring exponential space to solve
- C.Problems solvable in constant space only
- D.Problems with no space requirement at all
Explanation
PSPACE is the class of problems solvable by a Turing machine using a polynomial amount of space. P ⊆ NP ⊆ PSPACE.
Report an error in this question
Complexity & OptimizationMedium
Q16. What is loop unrolling?
- A.Removing all loops from the source code base entirely
- B.Making loops run in the reverse backward execution order
- C.Executing multiple iterations per loop cycle to reduce overhead✓ Correct
- D.Converting all iterative loops to recursion-based calls
Explanation
Loop unrolling is a compiler optimization that reduces loop overhead by executing the body of the loop multiple times per iteration, reducing the number of branch instructions.
Report an error in this question
Complexity & OptimizationMedium
Q17. Why is O(n log n) considered efficient for sorting?
- A.It works only for small input sizes efficiently
- B.It uses the least memory of all algorithms
- C.It matches the comparison-based sorting lower bound✓ Correct
- D.It is the fastest possible for all sorting
Explanation
O(n log n) is optimal for comparison-based sorting algorithms, as proven by the Ω(n log n) lower bound from decision tree analysis.
Report an error in this question
Complexity & OptimizationMedium
Q18. What is the difference between best case, worst case, and average case complexity?
- A.Best is minimum time, worst is maximum, average is expected✓ Correct
- B.Worst case is purely theoretical and never practical
- C.They are always the same value for any algorithm
- D.Best case only applies to small input sizes
Explanation
Best case is the minimum time for any input of size n, worst case is the maximum, and average case is the expected time averaged over all possible inputs.
Report an error in this question
Complexity & OptimizationMedium
Q19. What is cache-friendly code?
- A.Code with no memory access at all
- B.Code that runs entirely in cache memory
- C.Code that uses caching library APIs
- D.Code that maximizes CPU cache hit rates✓ Correct
Explanation
Cache-friendly code accesses memory sequentially or in patterns that maximize spatial and temporal locality, reducing cache misses and improving performance.
Report an error in this question
Complexity & OptimizationMedium
Q20. What is tail recursion optimization?
- A.Adding a tail data structure to the recursion stack
- B.Removing all recursive calls from the entire program
- C.Making recursive call the last operation for iteration optimization✓ Correct
- D.Making the recursion run in reverse backward order
Explanation
Tail recursion optimization converts a recursive function where the recursive call is the last operation into an iterative loop, eliminating stack overhead.
Report an error in this question
Complexity & OptimizationMedium
Q21. What is a polynomial reduction?
- A.Reducing the degree of a polynomial expression
- B.Transforming one problem into another in polynomial time✓ Correct
- C.Reducing the time complexity of an algorithm
- D.Simplifying an algorithm's code implementation
Explanation
A polynomial reduction transforms an instance of problem A into an instance of problem B in polynomial time, used to prove that B is at least as hard as A.
Report an error in this question
Complexity & OptimizationHard
Q22. What is Cook's theorem?
- A.P equals NP has been conclusively proven
- B.Every NP problem is fundamentally unsolvable
- C.Every problem is solvable in polynomial time
- D.The Boolean satisfiability problem (SAT) is NP-complete✓ Correct
Explanation
Cook's theorem (1971) proves that the Boolean satisfiability problem (SAT) is NP-complete, establishing the first known NP-complete problem.
Report an error in this question
Complexity & OptimizationHard
Q23. What is the approximation ratio of the 2-approximation algorithm for vertex cover?
- A.The solution is at most twice the optimal✓ Correct
- B.The solution is at most 1.5 times optimal
- C.The solution is at most 3 times the optimal
- D.The solution always equals the optimal exactly
Explanation
The greedy 2-approximation algorithm for vertex cover guarantees a solution at most twice the size of the optimal solution.
Report an error in this question
Complexity & OptimizationHard
Q24. What is the vertex cover problem?
- A.Coloring all vertices with minimum colors
- B.Finding all connected vertices in a graph
- C.Finding smallest vertex set covering all edges✓ Correct
- D.Covering all vertices with color assignments
Explanation
The vertex cover problem asks for the smallest set of vertices that covers all edges (every edge has at least one endpoint in the set). It is NP-complete.
Report an error in this question
Complexity & OptimizationHard
Q25. What is the difference between a decision problem and an optimization problem?
- A.Decision has yes/no answer; optimization seeks best solution✓ Correct
- B.They are exactly the same type of problem
- C.Optimization problems are always solvable in P
- D.Decision problems are always computationally harder
Explanation
A decision problem asks a yes/no question (e.g., 'Is there a path shorter than k?'). An optimization problem seeks the optimal solution (e.g., 'What is the shortest path?').
Report an error in this question
Complexity & OptimizationHard
Q26. What is pseudo-polynomial time?
- A.An algorithm that pretends to be efficient
- B.Time polynomial in input value rather than input size✓ Correct
- C.False polynomial time that does not exist
- D.The same as polynomial time in all cases
Explanation
A pseudo-polynomial algorithm runs in time polynomial in the value of the input (e.g., O(nW) for knapsack) but not in the size (number of bits) of the input.
Report an error in this question
Complexity & OptimizationHard
Q27. What is the 3-SAT problem?
- A.A Boolean satisfiability problem with 3 literals per clause✓ Correct
- B.A problem with exactly 3 valid solutions
- C.A sorting problem with 3 distinct elements
- D.Satisfying exactly 3 linear equations
Explanation
3-SAT is a special case of SAT where the Boolean formula is in CNF and each clause has exactly 3 literals. It is NP-complete and often used for reductions.
Report an error in this question
Complexity & OptimizationHard
Q28. What is the class co-NP?
- A.The class whose complement problems are in NP✓ Correct
- B.The complement of NP problems
- C.Problems that are harder than NP class
- D.Problems that are not in NP at all
Explanation
co-NP contains problems whose complement (negation) is in NP. For example, 'is this formula unsatisfiable?' is in co-NP because 'is it satisfiable?' is in NP.
Report an error in this question
Complexity & OptimizationHard
Q29. What is the time hierarchy theorem?
- A.All problems can be solved in the same time
- B.Time complexity is always fixed and unchanging
- C.More time allows a Turing machine to solve more problems✓ Correct
- D.There is no hierarchy in time complexity classes
Explanation
The time hierarchy theorem states that given more time, Turing machines can solve more problems. Specifically, DTIME(f(n)) is strictly contained in DTIME(f(n) × log f(n)) for reasonable f.
Report an error in this question
Complexity & OptimizationHard
Q30. What is a parameterized algorithm?
- A.An algorithm that dynamically changes its parameters at runtime
- B.An algorithm whose complexity depends on input size and a fixed parameter✓ Correct
- C.A tunable sorting algorithm that uses an adjustable pivot element
- D.An algorithm that has many user-tunable parameter values
Explanation
Parameterized algorithms measure complexity as f(k) × n^c, where k is a parameter. A problem is FPT if it can be solved in time f(k) × n^O(1), isolating the exponential part to the parameter k.
Report an error in this question