Analysis of Algorithms
Introduction
Learn to estimate algorithm efficiency and choose suitable strategies for solving computational problems.
Topic-Wise Overview
Complexity
Input size, asymptotic notation and algorithm analysis
Recurrences
Loop invariants, recursion and recurrence relations
Design Strategies
Brute force, divide and conquer, greedy methods and dynamic programming
Data and Graph Algorithms
Sorting, search trees, heaps, hashing and shortest paths
Advanced Analysis
String matching and introduction to complexity classes
Study Guidance
Now available: 200 Analysis of Algorithms MCQs in four sets of 50, each including four options, a correct answer and a short explanation. Topics include complexity, divide and conquer, sorting, graph algorithms, dynamic programming, string matching and complexity classes.
Start with the core definitions, follow practical examples and check your understanding with independent exercises. Topic-wise MCQs, short questions and step-by-step solutions are planned for this subject.
Explore Other Subjects
Browse Computer Science subjects
Analysis of Algorithms MCQs — Set 1 (Questions 1–50)
Answer each question, then reveal the correct option and a brief explanation.
Question 1. What does time complexity describe?
- How resource use grows with input size
- Exact wall-clock seconds on every computer
- Only memory allocated
- How long compilation takes
Show correct answer and explanation
Correct answer: A. How resource use grows with input size
Time complexity models operation growth as inputs increase.
Question 2. What is space complexity?
- Only processor speed
- Memory requirements as input size grows
- Network throughput
- Number of source-code files
Show correct answer and explanation
Correct answer: B. Memory requirements as input size grows
Space analysis estimates storage used by computation.
Question 3. Which notation gives an asymptotic upper bound?
- Big Omega only
- Theta only
- Big O
- Little omega only
Show correct answer and explanation
Correct answer: C. Big O
O(g(n)) means eventual growth is bounded above by a constant multiple of g(n).
Question 4. Which notation expresses an asymptotic lower bound?
- Big O only
- Theta only
- Little o only
- Big Omega
Show correct answer and explanation
Correct answer: D. Big Omega
Omega(g(n)) provides an eventual lower bound up to a positive factor.
Question 5. What does Theta(g(n)) mean?
- Both asymptotic upper and lower bounds of order g(n)
- Only an upper bound
- Only a strict lower bound
- Exact equality for all n
Show correct answer and explanation
Correct answer: A. Both asymptotic upper and lower bounds of order g(n)
Theta expresses a tight asymptotic growth rate.
Question 6. Which function grows fastest for large positive n?
- n^3
- 2^n
- n log n
- n^2
Show correct answer and explanation
Correct answer: B. 2^n
Exponential growth eventually dominates these polynomial and quasi-linear functions.
Question 7. Which is asymptotically smallest?
- sqrt n
- n
- log n
- n log n
Show correct answer and explanation
Correct answer: C. log n
The logarithm grows more slowly than positive power functions.
Question 8. What is O(1) running time?
- Exactly one CPU cycle
- Always faster than any linear program
- No memory required
- Bounded by a constant independent of input size
Show correct answer and explanation
Correct answer: D. Bounded by a constant independent of input size
Constant time is an asymptotic bound, not a fixed clock time.
Question 9. What is the complexity of a simple loop doing constant work n times?
- Theta(n)
- Theta(1)
- Theta(n squared)
- Theta(log n)
Show correct answer and explanation
Correct answer: A. Theta(n)
There are n iterations of constant cost.
Question 10. Two consecutive loops each of n iterations have total time
- Theta(n squared)
- Theta(n)
- Theta(log n)
- Theta(2^n)
Show correct answer and explanation
Correct answer: B. Theta(n)
Their combined 2n iterations grow linearly.
Question 11. Two nested loops each executing n times normally take
- Theta(n)
- Theta(log n)
- Theta(n squared)
- Theta(1)
Show correct answer and explanation
Correct answer: C. Theta(n squared)
There are n times n constant-work iterations.
Question 12. A loop repeatedly halving a positive n requires
- Theta(n) iterations
- Theta(n squared) iterations
- Theta(1) iterations for all n
- Theta(log n) iterations
Show correct answer and explanation
Correct answer: D. Theta(log n) iterations
Repeated division by two reaches one after logarithmically many steps.
Question 13. A loop doubling i from 1 while i is less than n has
- Theta(log n) iterations
- Theta(n) iterations
- Theta(n squared) iterations
- Theta(2^n) iterations
Show correct answer and explanation
Correct answer: A. Theta(log n) iterations
The number of doublings needed to reach n is logarithmic.
Question 14. The sum 1 + 2 + … + n is
- n squared exactly
- n(n+1)/2
- 2n
- n log n
Show correct answer and explanation
Correct answer: B. n(n+1)/2
This is the arithmetic-series identity.
Question 15. A triangular nested loop with inner iteration counts 1 through n has
- Theta(n) work
- Theta(log n) work
- Theta(n squared) work
- Theta(n cubed) work
Show correct answer and explanation
Correct answer: C. Theta(n squared) work
Its total iterations equal n(n+1)/2.
Question 16. What is a worst-case complexity bound?
- The average measured runtime
- The runtime of the smallest input only
- The minimum achievable cost
- A bound on maximum cost among inputs of size n
Show correct answer and explanation
Correct answer: D. A bound on maximum cost among inputs of size n
Worst-case analysis considers the most costly input at each size.
Question 17. What does best-case time measure?
- Minimum cost among inputs of a fixed size
- Maximum cost over all inputs
- Only expected cost
- Cost after compilation
Show correct answer and explanation
Correct answer: A. Minimum cost among inputs of a fixed size
Best-case analysis selects least expensive inputs.
Question 18. Average-case analysis requires
- Only the fastest example
- Assumptions or a distribution over inputs
- No model of inputs
- Worst-case inputs only
Show correct answer and explanation
Correct answer: B. Assumptions or a distribution over inputs
Expected running time depends on input probabilities.
Question 19. What does amortized analysis study?
- Mean CPU clock speed
- Only one fastest operation
- Average cost per operation over a sequence, without requiring an input probability distribution
- Only random algorithms
Show correct answer and explanation
Correct answer: C. Average cost per operation over a sequence, without requiring an input probability distribution
Occasional expensive operations can be offset by many cheap ones.
Question 20. What is the main role of a loop invariant?
- A value that must change each iteration
- A sorting algorithm
- A CPU instruction
- A property preserved between iterations supporting correctness
Show correct answer and explanation
Correct answer: D. A property preserved between iterations supporting correctness
Initialization, maintenance and termination establish a loop’s correctness.
Question 21. Which step of an invariant proof shows the property holds before the first loop iteration?
- Initialization
- Maintenance
- Termination
- Benchmarking
Show correct answer and explanation
Correct answer: A. Initialization
Initialization establishes the base case.
Question 22. Which step establishes that an invariant remains true after each iteration?
- Initialization
- Maintenance
- Allocation
- Compilation
Show correct answer and explanation
Correct answer: B. Maintenance
Maintenance proves preservation from one iteration to the next.
Question 23. Why does loop termination matter in a correctness proof?
- Termination eliminates all memory use
- Termination makes any invariant true
- A correct postcondition follows only when execution finishes, together with the invariant
- Termination is unrelated to correctness
Show correct answer and explanation
Correct answer: C. A correct postcondition follows only when execution finishes, together with the invariant
Total correctness includes both the desired result and termination.
Question 24. What is recursion?
- A loop without a condition
- Always a faster method
- Only a tree traversal
- Solving a problem by invoking the same procedure on smaller or related instances
Show correct answer and explanation
Correct answer: D. Solving a problem by invoking the same procedure on smaller or related instances
Recursion defines computations in terms of subproblems.
Question 25. Why is a base case necessary in typical recursion?
- To stop further recursive calls
- To increase stack use indefinitely
- To sort the input
- To change the programming language
Show correct answer and explanation
Correct answer: A. To stop further recursive calls
A base case supplies a direct solution that ends recursion.
Question 26. What recurrence models halving input size with constant extra work?
- T(n)=T(n-1)+Theta(n)
- T(n)=T(n/2)+Theta(1)
- T(n)=2T(n/2)+Theta(n)
- T(n)=T(n)+1
Show correct answer and explanation
Correct answer: B. T(n)=T(n/2)+Theta(1)
One half-size recursive call plus constant work gives logarithmic depth.
Question 27. What is the solution to T(n)=T(n-1)+Theta(1) with constant base cost?
- Theta(log n)
- Theta(n squared)
- Theta(n)
- Theta(2^n)
Show correct answer and explanation
Correct answer: C. Theta(n)
There are n constant-cost recursion levels.
Question 28. What is the solution to T(n)=2T(n/2)+Theta(n) for powers of two?
- Theta(n)
- Theta(n squared)
- Theta(log n)
- Theta(n log n)
Show correct answer and explanation
Correct answer: D. Theta(n log n)
Each recursion level costs Theta(n) over Theta(log n) levels.
Question 29. What is the solution to T(n)=T(n/2)+Theta(n)?
- Theta(n)
- Theta(n log n)
- Theta(log n)
- Theta(n squared)
Show correct answer and explanation
Correct answer: A. Theta(n)
The work forms a geometric series n+n/2+n/4+… .
Question 30. For T(n)=4T(n/2)+Theta(n), the tight bound is
- Theta(n log n)
- Theta(n squared)
- Theta(n)
- Theta(log n)
Show correct answer and explanation
Correct answer: B. Theta(n squared)
The recursion-tree leaves contribute Theta(n squared).
Question 31. Which technique repeatedly substitutes a hypothesized solution into a recurrence?
- Hashing
- Greedy choice
- Substitution method
- Heapification
Show correct answer and explanation
Correct answer: C. Substitution method
Substitution proves a recurrence bound using induction.
Question 32. What is a recursion tree used for?
- Allocating TCP ports
- Representing only program inheritance
- Choosing a pivot randomly
- Visualizing costs at recursive levels
Show correct answer and explanation
Correct answer: D. Visualizing costs at recursive levels
A recursion tree organizes subproblem costs by level.
Question 33. In the Master Theorem, which quantity is compared with f(n)?
- n raised to log base b of a
- n divided by a+b
- a times b squared
- log of f(n) only
Show correct answer and explanation
Correct answer: A. n raised to log base b of a
For T(n)=aT(n/b)+f(n), n^(log_b a) represents leaf-work scale.
Question 34. Which algorithmic method divides a problem into smaller independent subproblems?
- Always greedy choice
- Divide and conquer
- Only exhaustive enumeration
- Only memoization
Show correct answer and explanation
Correct answer: B. Divide and conquer
Divide and conquer solves and combines smaller instances.
Question 35. Which algorithm is a classic divide-and-conquer sorting method?
- Linear search
- Breadth-first search
- Merge sort
- Counting sort
Show correct answer and explanation
Correct answer: C. Merge sort
Merge sort recursively sorts halves then merges them.
Question 36. Merge sort has worst-case time complexity
- Theta(n squared)
- Theta(log n)
- Theta(1)
- Theta(n log n)
Show correct answer and explanation
Correct answer: D. Theta(n log n)
Balanced recursion and linear merging yield n log n time.
Question 37. Merge sort commonly requires extra array storage of
- Theta(n)
- Theta(1) in all implementations
- Theta(n squared)
- Theta(log log n)
Show correct answer and explanation
Correct answer: A. Theta(n)
Standard array merge sort uses linear auxiliary space.
Question 38. What is the worst-case time of standard quicksort?
- Theta(n log n) in every input
- Theta(n squared)
- Theta(n)
- Theta(log n)
Show correct answer and explanation
Correct answer: B. Theta(n squared)
Repeated unbalanced partitions can create quadratic work.
Question 39. What is the expected time of randomized quicksort?
- Theta(n squared)
- Theta(log n)
- Theta(n log n)
- Theta(1)
Show correct answer and explanation
Correct answer: C. Theta(n log n)
Randomized pivots provide expected balanced-enough partitions.
Question 40. The partition operation in quicksort primarily
- Creates a balanced search tree
- Merges two sorted halves
- Counts digit frequencies
- Rearranges elements relative to a pivot
Show correct answer and explanation
Correct answer: D. Rearranges elements relative to a pivot
Partitioning places values on appropriate sides of a pivot.
Question 41. Which property characterizes a stable sorting algorithm?
- Equal-key items preserve their relative order
- It always uses constant memory
- It always runs in linear time
- It cannot compare keys
Show correct answer and explanation
Correct answer: A. Equal-key items preserve their relative order
Stability keeps the original order of equivalent keys.
Question 42. Which sorting algorithm is stable in its standard implementation?
- Selection sort
- Insertion sort
- Heap sort
- Standard in-place quicksort
Show correct answer and explanation
Correct answer: B. Insertion sort
Insertion sort shifts larger keys without reversing equal ones.
Question 43. Insertion sort’s best-case time on sorted input is
- Theta(n log n)
- Theta(n squared)
- Theta(n)
- Theta(1)
Show correct answer and explanation
Correct answer: C. Theta(n)
Each successive element needs only a constant-cost check.
Question 44. Insertion sort’s worst-case time is
- Theta(log n)
- Theta(n log n)
- Theta(2^n)
- Theta(n squared)
Show correct answer and explanation
Correct answer: D. Theta(n squared)
Reverse-sorted inputs produce quadratically many shifts.
Question 45. Selection sort normally performs comparisons on the order of
- Theta(n squared)
- Theta(n)
- Theta(log n)
- Theta(1)
Show correct answer and explanation
Correct answer: A. Theta(n squared)
It scans the unsorted suffix for each position.
Question 46. Heap sort’s worst-case time is
- Theta(n squared)
- Theta(n log n)
- Theta(n)
- Theta(2^n)
Show correct answer and explanation
Correct answer: B. Theta(n log n)
Building a heap and repeated logarithmic removals give n log n.
Question 47. A binary max-heap requires every parent key to be
- At most as large as its children’s keys
- Equal to every leaf
- At least as large as its children’s keys
- Smaller than every descendant
Show correct answer and explanation
Correct answer: C. At least as large as its children’s keys
The max-heap order condition applies at every parent.
Question 48. Which heap operation retrieves the maximum key in a max-heap in O(1) time?
- Extracting all elements
- Building a new heap
- Sorting the heap
- Inspecting the root
Show correct answer and explanation
Correct answer: D. Inspecting the root
The maximum is stored at the root.
Question 49. Which lower bound applies to comparison-based sorting in the worst case?
- Omega(n log n)
- Omega(n squared)
- Omega(2^n)
- Omega(n cubed)
Show correct answer and explanation
Correct answer: A. Omega(n log n)
A decision tree requires distinguishing n! possible permutations.
Question 50. What is counting sort’s typical running time when key range size is k?
- Theta(n log n)
- Theta(n+k)
- Theta(n squared) always
- Theta(log n)
Show correct answer and explanation
Correct answer: B. Theta(n+k)
Counting frequencies and reconstructing output take linear time in n+k.
Analysis of Algorithms MCQs — Set 2 (Questions 51–100)
Read each question and reveal the correct answer with a short explanation.
Question 51. Linear search worst-case time?
- Theta(log n)
- Theta(1)
- Theta(n)
- Theta(n squared)
Show correct answer and explanation
Correct answer: C. Theta(n)
An unsuccessful scan can examine all n elements.
Question 52. Binary search prerequisite?
- Randomly ordered records
- A prime number of elements
- A linked list necessarily
- A sorted search range
Show correct answer and explanation
Correct answer: D. A sorted search range
Binary search discards halves using ordered comparisons.
Question 53. Binary search worst-case time?
- Theta(log n)
- Theta(n)
- Theta(n squared)
- Theta(1)
Show correct answer and explanation
Correct answer: A. Theta(log n)
The search interval halves repeatedly.
Question 54. A balanced BST search typically costs?
- O(n squared)
- O(log n)
- O(2^n)
- O(n) necessarily
Show correct answer and explanation
Correct answer: B. O(log n)
Balanced height grows logarithmically.
Question 55. A skewed BST search can cost?
- Theta(log n) always
- Theta(1)
- Theta(n)
- Theta(n squared)
Show correct answer and explanation
Correct answer: C. Theta(n)
A degenerate BST can be a chain.
Question 56. Which BST traversal yields increasing keys?
- Preorder
- Postorder
- Level order
- Inorder
Show correct answer and explanation
Correct answer: D. Inorder
Inorder visits left, root and right.
Question 57. AVL trees maintain?
- Height balance using rotations
- Perfectly full levels always
- Hash-table buckets
- Only a max-heap property
Show correct answer and explanation
Correct answer: A. Height balance using rotations
AVL rotations preserve logarithmic height.
Question 58. Red-black trees have maximum height of order?
- Theta(n squared)
- O(log n)
- Theta(2^n)
- Theta(1)
Show correct answer and explanation
Correct answer: B. O(log n)
Color and path invariants ensure balance.
Question 59. A hash collision happens when?
- A key is deleted
- Every bucket is empty
- Distinct keys map to the same slot
- Keys are sorted
Show correct answer and explanation
Correct answer: C. Distinct keys map to the same slot
A finite hash range may map different keys together.
Question 60. Separate chaining stores collisions?
- Only in a binary heap
- By deleting all duplicate slots
- In a sorted single array only
- In collections associated with buckets
Show correct answer and explanation
Correct answer: D. In collections associated with buckets
Each bucket can hold multiple entries.
Question 61. Open addressing handles collisions by?
- Searching alternate table slots
- Always allocating a linked list
- Refusing second keys
- Changing every hash key
Show correct answer and explanation
Correct answer: A. Searching alternate table slots
Probing finds alternative locations.
Question 62. Hash-table load factor measures?
- Maximum key value
- Entries divided by capacity
- Number of hash functions
- CPU time
Show correct answer and explanation
Correct answer: B. Entries divided by capacity
Load factor describes occupancy.
Question 63. Expected hash lookup with suitable hashing is?
- O(n squared)
- O(2^n)
- O(1)
- O(n log n)
Show correct answer and explanation
Correct answer: C. O(1)
Uniform hashing and controlled load support constant expected access.
Question 64. A binary heap supports?
- Only key-value hashing
- Only graph reachability
- Regular expression parsing
- Priority queue operations
Show correct answer and explanation
Correct answer: D. Priority queue operations
Heaps efficiently maintain minimum or maximum priority.
Question 65. Bottom-up heap construction takes?
- Theta(n)
- Theta(n log n)
- Theta(n squared)
- Theta(log n)
Show correct answer and explanation
Correct answer: A. Theta(n)
Most nodes lie near leaves with low sift-down cost.
Question 66. Binary heap insertion worst-case cost?
- O(n squared)
- O(log n)
- O(2^n)
- O(1) necessarily
Show correct answer and explanation
Correct answer: B. O(log n)
An item may travel up the heap height.
Question 67. Extract-min on binary min-heap costs?
- O(1) always
- O(n squared)
- O(log n)
- O(2^n)
Show correct answer and explanation
Correct answer: C. O(log n)
Restoring heap order may traverse the heap height.
Question 68. DFS is naturally implemented with?
- FIFO queue only
- Sorting network
- Hash table only
- Stack or recursion
Show correct answer and explanation
Correct answer: D. Stack or recursion
Depth-first exploration follows stack discipline.
Question 69. BFS uses which frontier structure?
- FIFO queue
- Stack only
- Min-heap by weight only
- Binary search tree necessarily
Show correct answer and explanation
Correct answer: A. FIFO queue
BFS visits nodes by increasing edge distance.
Question 70. BFS on unweighted graphs finds?
- Always minimum-cost weighted paths
- Shortest paths by number of edges
- Only spanning trees of minimum weight
- Only topological orders
Show correct answer and explanation
Correct answer: B. Shortest paths by number of edges
Equal edge costs make shortest hop count optimal.
Question 71. BFS adjacency-list complexity?
- O(V times E squared)
- O(2^V)
- O(V+E)
- O(log V) for every graph
Show correct answer and explanation
Correct answer: C. O(V+E)
Every vertex and edge is processed a bounded number of times.
Question 72. DFS adjacency-list complexity?
- O(V cubed)
- O(2^E)
- O(log V) universally
- O(V+E)
Show correct answer and explanation
Correct answer: D. O(V+E)
DFS scans each adjacency list.
Question 73. A topological ordering exists for?
- Directed acyclic graph
- Every directed graph
- Every connected undirected graph
- Every cyclic digraph
Show correct answer and explanation
Correct answer: A. Directed acyclic graph
Cycles contradict a consistent edge precedence order.
Question 74. Kahn’s topological algorithm starts with?
- Maximum-weight vertices
- Zero-indegree vertices
- Sink vertices only
- Random edges
Show correct answer and explanation
Correct answer: B. Zero-indegree vertices
Removing zero-indegree vertices yields an ordering.
Question 75. A strongly connected component contains?
- Only equal-weight edges
- A minimum spanning tree
- Mutually reachable directed vertices
- Vertices of equal degree only
Show correct answer and explanation
Correct answer: C. Mutually reachable directed vertices
Each pair of its vertices can reach one another.
Question 76. Which method computes strongly connected components?
- Kruskal’s algorithm
- Quickselect
- Counting sort
- Kosaraju’s algorithm
Show correct answer and explanation
Correct answer: D. Kosaraju’s algorithm
Kosaraju uses graph traversals in two passes.
Question 77. Dijkstra requires for its standard optimality guarantee?
- Nonnegative edge weights
- All negative weights
- An acyclic network
- One edge per vertex
Show correct answer and explanation
Correct answer: A. Nonnegative edge weights
Negative edges can violate greedy distance finalization.
Question 78. Bellman-Ford can accommodate?
- Only nonnegative edges
- Negative edge weights without reachable negative cycles yielding undefined finite distances
- Only undirected trees
- Only constant-weight graphs
Show correct answer and explanation
Correct answer: B. Negative edge weights without reachable negative cycles yielding undefined finite distances
Repeated edge relaxation handles negatives.
Question 79. Bellman-Ford standard complexity?
- O(log V)
- O(E squared V squared)
- O(VE)
- O(1)
Show correct answer and explanation
Correct answer: C. O(VE)
The algorithm performs up to V minus 1 full edge-relaxation rounds.
Question 80. Floyd-Warshall solves?
- Only minimum spanning trees
- Only linear search
- Only graph coloring
- All-pairs shortest paths
Show correct answer and explanation
Correct answer: D. All-pairs shortest paths
It uses intermediate vertices in a dynamic program.
Question 81. Floyd-Warshall time complexity?
- Theta(V cubed)
- Theta(V+E)
- Theta(log V)
- Theta(V factorial)
Show correct answer and explanation
Correct answer: A. Theta(V cubed)
Three loops range over graph vertices.
Question 82. An MST is defined for?
- Only directed cycles
- Connected undirected weighted graphs
- Only sorted arrays
- Only strings
Show correct answer and explanation
Correct answer: B. Connected undirected weighted graphs
An MST connects every vertex without cycles at minimum total weight.
Question 83. Prim’s algorithm builds?
- A suffix array
- A maximum-flow network necessarily
- A minimum spanning tree
- An all-pairs distance matrix
Show correct answer and explanation
Correct answer: C. A minimum spanning tree
Prim repeatedly adds a light edge from the current tree.
Question 84. Kruskal’s algorithm processes edges?
- By decreasing vertex ID
- By random priority
- Only by breadth-first depth
- By increasing weight while avoiding cycles
Show correct answer and explanation
Correct answer: D. By increasing weight while avoiding cycles
Acyclic safe edges grow the spanning forest.
Question 85. Kruskal commonly uses?
- Disjoint-set union
- A trie
- Only a stack of strings
- Only a queue of queries
Show correct answer and explanation
Correct answer: A. Disjoint-set union
Union-find detects whether endpoints are already connected.
Question 86. Union-find supports?
- Only sorting
- Find and union operations
- Only binary searching
- Only shortest-path relaxation
Show correct answer and explanation
Correct answer: B. Find and union operations
It tracks disjoint component partitions.
Question 87. Path compression with union by rank offers?
- Always quadratic time
- Exponential time
- Nearly constant amortized operations
- Exactly O(log n) worst-case per operation in all models
Show correct answer and explanation
Correct answer: C. Nearly constant amortized operations
The inverse Ackermann function grows extremely slowly.
Question 88. The MST cut property justifies choosing?
- The heaviest edge of every cycle
- Only edges with negative weights
- Only edges from vertex 1
- A minimum-weight crossing edge for a suitable cut
Show correct answer and explanation
Correct answer: D. A minimum-weight crossing edge for a suitable cut
A light crossing edge is safe for some MST.
Question 89. A greedy algorithm makes?
- A locally preferred choice at each step
- Every possible sequence of choices
- Only randomized choices
- A guaranteed optimal choice for every problem
Show correct answer and explanation
Correct answer: A. A locally preferred choice at each step
Optimality needs a greedy-choice proof.
Question 90. Unweighted interval scheduling favors?
- Longest activity
- Earliest finishing compatible activity
- Latest ending activity
- Random intervals
Show correct answer and explanation
Correct answer: B. Earliest finishing compatible activity
Earliest completion leaves more available time.
Question 91. Fractional knapsack can be solved greedily by?
- Always smallest item weight
- Descending total value only
- Descending value-to-weight ratio
- Random item order
Show correct answer and explanation
Correct answer: C. Descending value-to-weight ratio
Fractions allow selecting the most valuable density first.
Question 92. The classical 0/1 knapsack capacity DP has?
- Guaranteed O(log n) time
- Constant time
- Exponential time for every numeric capacity
- Pseudopolynomial dependence on capacity
Show correct answer and explanation
Correct answer: D. Pseudopolynomial dependence on capacity
A table over items and capacity states solves it.
Question 93. Dynamic programming is useful with?
- Overlapping subproblems and optimal substructure
- Only disjoint subproblems always
- Only graph cycles
- Only random inputs
Show correct answer and explanation
Correct answer: A. Overlapping subproblems and optimal substructure
DP reuses subproblem solutions.
Question 94. Memoization computes subproblems?
- Only with bottom-up loops
- On demand and caches results
- Without saving results
- Only for sorting
Show correct answer and explanation
Correct answer: B. On demand and caches results
Memoization avoids repeated evaluation.
Question 95. Tabulation computes solutions?
- Using only recursion with no table
- By always taking a greedy choice
- Bottom-up in a dependency-respecting order
- Using only random sampling
Show correct answer and explanation
Correct answer: C. Bottom-up in a dependency-respecting order
A table is filled in an appropriate subproblem order.
Question 96. LCS dynamic programming finds?
- Minimum spanning tree weight
- Maximum hash value
- Only prefix frequencies
- Longest common subsequence length
Show correct answer and explanation
Correct answer: D. Longest common subsequence length
The recurrence compares prefixes of two sequences.
Question 97. A longest common subsequence need not be?
- Contiguous
- In relative order
- Shared by both sequences
- Finite for finite strings
Show correct answer and explanation
Correct answer: A. Contiguous
Subsequences preserve order but may skip characters.
Question 98. The edit-distance DP commonly includes operations?
- Only multiplication
- Insertion deletion and substitution
- Only sorting by value
- Only matrix transposition
Show correct answer and explanation
Correct answer: B. Insertion deletion and substitution
Levenshtein distance counts edit operations.
Question 99. With n and m string lengths, standard LCS DP takes?
- Theta(n+m) always
- Theta(log nm)
- Theta(nm) time
- Theta(2^n) necessarily
Show correct answer and explanation
Correct answer: C. Theta(nm) time
It fills n times m subproblem states.
Question 100. The main optimal-substructure idea is?
- Every input must be sorted
- All subproblems have equal sizes
- Any greedy rule is optimal
- An optimal solution can be built using optimal subproblem solutions
Show correct answer and explanation
Correct answer: D. An optimal solution can be built using optimal subproblem solutions
It enables recursive formulations for DP.
Analysis of Algorithms MCQs — Set 3 (Questions 101–150)
Choose an answer and reveal its explanation.
Question 101. LCS of ABC and AC length?
- 2
- 1
- 3
- 0
Show correct answer and explanation
Correct answer: A. 2
AC is common subsequence length two.
Question 102. Edit distance cat to cut?
- 0
- 1
- 2
- 3
Show correct answer and explanation
Correct answer: B. 1
One substitution suffices.
Question 103. DP state represents?
- CPU register only
- Source file only
- Reusable subproblem
- Final result only
Show correct answer and explanation
Correct answer: C. Reusable subproblem
DP stores solutions to subproblems.
Question 104. Rolling-array DP reduces?
- All runtime
- All errors
- Every loop
- Auxiliary memory
Show correct answer and explanation
Correct answer: D. Auxiliary memory
It stores only needed previous rows.
Question 105. Top-down DP uses?
- Memoized recursion
- Only greedy choices
- No caching
- Only sorting
Show correct answer and explanation
Correct answer: A. Memoized recursion
Recursive results are cached.
Question 106. Minimum-coin change seeks?
- Largest coin
- Fewest coins for a sum
- Longest list
- Smallest denomination only
Show correct answer and explanation
Correct answer: B. Fewest coins for a sum
It minimizes the coin count.
Question 107. Unbounded knapsack allows?
- Only one copy
- Fractions only
- Multiple copies of each item type
- Unlimited capacity
Show correct answer and explanation
Correct answer: C. Multiple copies of each item type
Items can repeat.
Question 108. Quadratic LIS DP cost?
- Theta(n)
- Theta(log n)
- Theta(2^n)
- Theta(n squared)
Show correct answer and explanation
Correct answer: D. Theta(n squared)
Each element checks earlier elements.
Question 109. Efficient LIS length cost?
- O(n log n)
- O(n squared) always
- O(1)
- O(2^n)
Show correct answer and explanation
Correct answer: A. O(n log n)
Binary search updates tails.
Question 110. Matrix chain DP minimizes?
- Number of matrices
- Scalar multiplication count
- Value of entries
- Number of dimensions
Show correct answer and explanation
Correct answer: B. Scalar multiplication count
Costs depend on parenthesization.
Question 111. Parenthesization counts use?
- Prime numbers
- Fibonacci exactly
- Catalan numbers
- Powers of two exactly
Show correct answer and explanation
Correct answer: C. Catalan numbers
Catalan numbers count binary structures.
Question 112. Optimal substructure?
- All keys sorted
- All choices greedy
- All paths equal
- Optimal solutions contain optimal subsolutions
Show correct answer and explanation
Correct answer: D. Optimal solutions contain optimal subsolutions
DP exploits optimal subproblem results.
Question 113. Huffman merges?
- Two least-frequency nodes
- Two largest
- Random nodes
- First two alphabetically
Show correct answer and explanation
Correct answer: A. Two least-frequency nodes
Greedy merging minimizes weighted code length.
Question 114. Prefix-free coding means?
- Every word starts with 0
- No codeword prefixes another
- All words equal length
- Only ASCII
Show correct answer and explanation
Correct answer: B. No codeword prefixes another
Decoding is unambiguous.
Question 115. Greedy exchange argument?
- Measures time
- Changes hardware
- Replaces a choice in an optimum without losing quality
- Counts code lines
Show correct answer and explanation
Correct answer: C. Replaces a choice in an optimum without losing quality
It justifies a greedy choice.
Question 116. Counterexample can?
- Prove correctness for all cases
- Guarantee runtime
- Avoid proof
- Disprove universal correctness
Show correct answer and explanation
Correct answer: D. Disprove universal correctness
One failing input refutes universal claims.
Question 117. Weighted interval scheduling uses?
- Dynamic programming
- Earliest finish alone always
- Only BFS
- Only Kruskal
Show correct answer and explanation
Correct answer: A. Dynamic programming
Weights require considering choices.
Question 118. DAG shortest paths use?
- Random order
- Topological relaxation
- Kruskal
- Only max-heap
Show correct answer and explanation
Correct answer: B. Topological relaxation
Topological order respects predecessor processing.
Question 119. Negative edges on a DAG?
- Always cause negative cycles
- Need complete graph
- Can be handled by topological shortest paths
- Forbid algorithms
Show correct answer and explanation
Correct answer: C. Can be handled by topological shortest paths
DAGs have no directed cycles.
Question 120. Reachable negative cycle may give?
- All zero distances
- Only positive routes
- Unique paths
- Unboundedly decreasing path costs
Show correct answer and explanation
Correct answer: D. Unboundedly decreasing path costs
Repeating the cycle lowers cost.
Question 121. Edge relaxation attempts?
- Improve a distance estimate
- Delete edges
- Sort vertices
- Count cycles
Show correct answer and explanation
Correct answer: A. Improve a distance estimate
It checks a better route via an edge.
Question 122. Dijkstra priority queue selects?
- Highest degree
- Lowest tentative distance
- Longest edge
- Random vertex
Show correct answer and explanation
Correct answer: B. Lowest tentative distance
Extract-min implements greedy settling.
Question 123. Binary-heap Dijkstra cost?
- O(log V) universally
- O(V factorial)
- O((V+E) log V)
- O(1)
Show correct answer and explanation
Correct answer: C. O((V+E) log V)
Queue operations dominate this bound.
Question 124. Single-source shortest paths?
- Only minimum cuts
- Only diameters
- Only colorings
- Distances from one selected source
Show correct answer and explanation
Correct answer: D. Distances from one selected source
The problem fixes one origin.
Question 125. All-pairs shortest paths?
- Distances for every vertex pair
- Only one source
- Only MST edges
- Only a BFS tree
Show correct answer and explanation
Correct answer: A. Distances for every vertex pair
All sources are considered.
Question 126. Connected unweighted diameter?
- Maximum degree
- Largest shortest-path hop distance
- Total edges
- Minimum edge weight
Show correct answer and explanation
Correct answer: B. Largest shortest-path hop distance
It maximizes distance over vertex pairs.
Question 127. BFS tree depth?
- Equals arbitrary weighted cost
- Equals degree
- Equals hop distance from root
- Equals graph diameter
Show correct answer and explanation
Correct answer: C. Equals hop distance from root
BFS searches level by level.
Question 128. Undirected tree?
- Complete graph
- Any cycle
- Always regular
- Connected acyclic graph
Show correct answer and explanation
Correct answer: D. Connected acyclic graph
Both connectivity and acyclicity are required.
Question 129. Edges in n-vertex tree?
- n-1
- n
- n+1
- n squared
Show correct answer and explanation
Correct answer: A. n-1
Trees have one fewer edge than vertices.
Question 130. Spanning tree?
- Includes all original edges
- Covers all vertices without cycles
- Contains one vertex
- Always complete
Show correct answer and explanation
Correct answer: B. Covers all vertices without cycles
It is a tree covering the graph.
Question 131. Bridge?
- Every cycle edge
- Heaviest edge
- Edge removal increases connected components
- Self-loop
Show correct answer and explanation
Correct answer: C. Edge removal increases connected components
Bridges are critical connections.
Question 132. Articulation vertex?
- Always highest-degree vertex
- Any leaf
- Any triangle vertex
- Removal increases component count
Show correct answer and explanation
Correct answer: D. Removal increases component count
A cut vertex disrupts connectivity.
Question 133. Maximum edges in simple graph on n vertices?
- n(n-1)/2
- n squared
- 2n
- n-1
Show correct answer and explanation
Correct answer: A. n(n-1)/2
One possible edge per unordered vertex pair.
Question 134. Edges in K5?
- 5
- 10
- 15
- 20
Show correct answer and explanation
Correct answer: B. 10
Five choose two equals ten.
Question 135. Bipartite edges lie?
- Inside one class
- Only as self-loops
- Across two vertex classes
- Only in triangles
Show correct answer and explanation
Correct answer: C. Across two vertex classes
Both vertex classes are independent.
Question 136. Bipartite graphs have?
- No even cycles
- Exactly two vertices
- Only degree one
- No odd cycles
Show correct answer and explanation
Correct answer: D. No odd cycles
Odd cycles obstruct two coloring.
Question 137. Bipartiteness testing?
- BFS two-coloring
- Quicksort
- Only Dijkstra
- Heap insertion
Show correct answer and explanation
Correct answer: A. BFS two-coloring
Opposite colors must be assigned across each edge.
Question 138. Maximum matching?
- Any inclusion-maximal matching
- Largest matching cardinality
- An MST
- All edges
Show correct answer and explanation
Correct answer: B. Largest matching cardinality
Maximum is globally largest.
Question 139. Maximal matching?
- Always maximum
- Always perfect
- Cannot add another edge while preserving matching
- Always empty
Show correct answer and explanation
Correct answer: C. Cannot add another edge while preserving matching
Maximal is inclusion-wise.
Question 140. Augmenting path?
- Only matched edges
- Always a cycle
- Only weighted edges
- Alternates matched and unmatched edges with free endpoints
Show correct answer and explanation
Correct answer: D. Alternates matched and unmatched edges with free endpoints
Flipping membership increases matching size.
Question 141. Max-flow goal?
- Maximum feasible source-sink flow
- Minimum path length
- Maximum number of vertices
- Only MST
Show correct answer and explanation
Correct answer: A. Maximum feasible source-sink flow
Capacity and conservation constrain flow.
Question 142. Residual network represents?
- Only graph labels
- Permitted flow adjustments
- A BFS tree only
- Only original edge weights
Show correct answer and explanation
Correct answer: B. Permitted flow adjustments
Residual capacities show possible changes.
Question 143. Ford-Fulkerson repeats?
- Quicksort
- Minimum cuts without flows
- Residual augmenting-path updates
- Only DFS traversal
Show correct answer and explanation
Correct answer: C. Residual augmenting-path updates
Each augmentation increases flow.
Question 144. Max-flow min-cut theorem?
- All cuts equal
- Flow equals V
- All capacities equal
- Max flow value equals min cut capacity
Show correct answer and explanation
Correct answer: D. Max flow value equals min cut capacity
The optimum values coincide.
Question 145. Edmonds-Karp time?
- O(V E squared)
- O(V+E)
- O(log V)
- O(V factorial)
Show correct answer and explanation
Correct answer: A. O(V E squared)
BFS path augmentation gives O(VE²).
Question 146. Disjoint set union supports?
- Only sort
- Find and union
- Only edit-distance DP
- Only topological order
Show correct answer and explanation
Correct answer: B. Find and union
DSU manages disjoint components.
Question 147. Union by rank is used to?
- Increase tree depth
- Sort all elements
- Keep disjoint-set trees shallow
- Find cycles without any unions
Show correct answer and explanation
Correct answer: C. Keep disjoint-set trees shallow
Rank heuristics limit depth.
Question 148. Path compression does?
- Adds graph edges
- Removes heap nodes
- Chooses MST weights
- Shortens parent paths during find
Show correct answer and explanation
Correct answer: D. Shortens parent paths during find
It accelerates later DSU queries.
Question 149. MST cut property permits?
- A minimum crossing edge as a safe choice
- The heaviest crossing edge always
- Only edges in cycles
- Only negative edges
Show correct answer and explanation
Correct answer: A. A minimum crossing edge as a safe choice
Light edges crossing appropriate cuts are safe.
Question 150. Kruskal’s algorithm applies DSU to?
- Find longest common subsequences
- Avoid selecting cycle-forming edges
- Sort strings
- Compute matrix inverse
Show correct answer and explanation
Correct answer: B. Avoid selecting cycle-forming edges
Components identify connected endpoints.
Analysis of Algorithms MCQs — Set 4 (Questions 151–200)
Choose an answer and reveal the explanation.
Question 151. Naive string matching worst-case time for text n pattern m?
- O(n+m) always
- O(log n)
- O(nm)
- O(1)
Show correct answer and explanation
Correct answer: C. O(nm)
It may compare m characters at each alignment.
Question 152. KMP pattern matching uses?
- A maximum spanning tree
- Only randomized pivots
- A hash table necessarily
- Prefix-function or failure information
Show correct answer and explanation
Correct answer: D. Prefix-function or failure information
Preprocessed borders avoid repeating comparisons.
Question 153. KMP total time for length n text and m pattern?
- O(n+m)
- O(nm) necessarily
- O(n squared m)
- O(log n)
Show correct answer and explanation
Correct answer: A. O(n+m)
Prefix preprocessing and scanning are linear.
Question 154. Rabin-Karp searches using?
- Only heap order
- Rolling hash values
- Greedy spanning trees
- Depth-first traversal
Show correct answer and explanation
Correct answer: B. Rolling hash values
Hashes efficiently filter candidate matches.
Question 155. A spurious hit in Rabin-Karp occurs when?
- A substring truly matches
- The text ends
- Different strings have equal hash values
- A key is deleted
Show correct answer and explanation
Correct answer: C. Different strings have equal hash values
Hash collisions require verifying candidate matches.
Question 156. Finite automaton string matching uses?
- Only sorted graph edges
- Matrix-chain DP
- A max-flow residual graph
- State transitions representing pattern-prefix progress
Show correct answer and explanation
Correct answer: D. State transitions representing pattern-prefix progress
An automaton tracks matched prefix length.
Question 157. A trie is useful for?
- Prefix-based string lookup
- Finding MSTs by weights
- Numerical integration
- Only sorting floating values
Show correct answer and explanation
Correct answer: A. Prefix-based string lookup
Trie paths represent successive symbols.
Question 158. A suffix array stores?
- All prefix sums
- Suffix starting positions in lexicographic order
- Only unique characters
- A table of hash collisions
Show correct answer and explanation
Correct answer: B. Suffix starting positions in lexicographic order
Suffixes are indexed in sorted order.
Question 159. Longest common prefix of two strings is?
- A common subsequence with gaps
- Their edit distance
- The maximum-length shared initial segment
- The number of differing characters
Show correct answer and explanation
Correct answer: C. The maximum-length shared initial segment
A prefix begins at the first position of each string.
Question 160. A rolling hash supports?
- Sorting all graph vertices
- Removing all collision possibilities
- Finding every MST
- Efficiently updating a substring hash as the window moves
Show correct answer and explanation
Correct answer: D. Efficiently updating a substring hash as the window moves
Arithmetic can adjust the hash when one character leaves and another enters.
Question 161. Randomized algorithms use?
- Random choices during computation
- Only random input sizes
- No correctness arguments
- Always exponential time
Show correct answer and explanation
Correct answer: A. Random choices during computation
Randomness may influence execution paths.
Question 162. Las Vegas algorithms typically provide?
- Possibly incorrect results with fixed cost only
- Always correct results with random running time
- No termination possible
- Only approximate solutions
Show correct answer and explanation
Correct answer: B. Always correct results with random running time
Las Vegas randomness affects runtime rather than correctness.
Question 163. Monte Carlo algorithms may?
- Guarantee correctness on every run
- Never use random bits
- Produce a bounded probability of an incorrect result
- Require exponential storage
Show correct answer and explanation
Correct answer: C. Produce a bounded probability of an incorrect result
Monte Carlo methods trade controlled error probability for performance.
Question 164. Randomized quicksort randomizes?
- Every comparison outcome
- Array elements’ values
- The definition of sorted order
- Pivot selection
Show correct answer and explanation
Correct answer: D. Pivot selection
Random pivot choice improves expected partition behavior.
Question 165. Expected randomized quicksort comparisons are?
- Theta(n log n)
- Theta(n squared) always
- Theta(1)
- Theta(2^n)
Show correct answer and explanation
Correct answer: A. Theta(n log n)
The average over random pivot choices is n log n.
Question 166. Hashing with universal families aims to?
- Eliminate all possible collisions
- Limit collisions in expectation over randomly chosen hash functions
- Force every key into one bucket
- Sort keys automatically
Show correct answer and explanation
Correct answer: B. Limit collisions in expectation over randomly chosen hash functions
A suitable random family bounds collision probability.
Question 167. Reservoir sampling selects?
- Every item
- Only the first item
- A uniform sample from streaming items without knowing stream length in advance
- Only the largest item
Show correct answer and explanation
Correct answer: C. A uniform sample from streaming items without knowing stream length in advance
The reservoir is updated probabilistically.
Question 168. A bloom filter supports?
- Exact ordered range queries
- Guaranteed no false positives for every parameter
- Deletion in every basic design
- Probabilistic membership queries with possible false positives
Show correct answer and explanation
Correct answer: D. Probabilistic membership queries with possible false positives
Bloom filters trade compact storage for false positives.
Question 169. A standard bloom filter may report?
- Possibly present for an absent element
- Definitely absent for an inserted element in a correctly maintained filter
- Only sorted answers
- A numeric shortest path
Show correct answer and explanation
Correct answer: A. Possibly present for an absent element
Hash-bit collisions can produce false positives.
Question 170. An approximation algorithm seeks?
- An exact answer in every NP-hard problem
- A solution with a provable bound relative to optimum
- Only randomness
- Only an exponential algorithm
Show correct answer and explanation
Correct answer: B. A solution with a provable bound relative to optimum
Approximation ratios quantify solution quality.
Question 171. A 2-approximation for minimization returns cost at most?
- Half the optimum
- Exactly optimal always
- Twice the optimum
- Four times the optimum necessarily
Show correct answer and explanation
Correct answer: C. Twice the optimum
The approximation guarantee upper-bounds cost by 2 OPT.
Question 172. What is an online algorithm?
- An algorithm requiring all input beforehand
- Only a web application
- A distributed database only
- An algorithm making decisions as data arrive
Show correct answer and explanation
Correct answer: D. An algorithm making decisions as data arrive
Online algorithms act without seeing all future data.
Question 173. Competitive analysis compares?
- Online algorithm cost with optimal offline cost
- Only CPU brand names
- Only worst-case memory
- Source-code line counts
Show correct answer and explanation
Correct answer: A. Online algorithm cost with optimal offline cost
Competitive ratios benchmark against future-aware optimum.
Question 174. A streaming algorithm generally seeks?
- Storing the entire stream necessarily
- Processing data with small memory while items arrive
- Sorting every possible permutation
- No approximation ever
Show correct answer and explanation
Correct answer: B. Processing data with small memory while items arrive
Streaming methods operate under limited storage.
Question 175. A divide-and-conquer algorithm can be parallelized when?
- Every recursive call depends sequentially on previous results
- There is only one processor
- Subproblems can be processed independently
- All data are stored on disk
Show correct answer and explanation
Correct answer: C. Subproblems can be processed independently
Independent branches can execute concurrently.
Question 176. Amdahl’s law bounds?
- Only number of recursion leaves
- All sorting comparisons
- Hash table occupancy
- Parallel speedup due to the serial fraction
Show correct answer and explanation
Correct answer: D. Parallel speedup due to the serial fraction
Serial work limits speedup.
Question 177. If serial fraction is 0.25 the infinite-core speedup bound is?
- 4
- 2
- 8
- Unlimited
Show correct answer and explanation
Correct answer: A. 4
1 divided by 0.25 equals 4.
Question 178. Work in parallel-algorithm analysis means?
- Only longest dependency path
- Total operations across processors
- Only memory size
- Wall time on one fixed processor
Show correct answer and explanation
Correct answer: B. Total operations across processors
Work counts aggregate computational effort.
Question 179. Span in a computation DAG means?
- Total number of edges in input graph always
- Only number of CPUs
- Length of the longest dependency chain
- Average key value
Show correct answer and explanation
Correct answer: C. Length of the longest dependency chain
Span is critical-path parallel time.
Question 180. Brent’s theorem relates?
- Only matrix multiplication dimensions
- Only greedy choice
- String hash collisions
- Parallel running time to work span and processor count
Show correct answer and explanation
Correct answer: D. Parallel running time to work span and processor count
Work and span provide scheduling bounds.
Question 181. Potential method in amortized analysis uses?
- A stored potential function to account for future costs
- Only random variables
- A shortest-path priority queue
- A network prefix
Show correct answer and explanation
Correct answer: A. A stored potential function to account for future costs
Potential changes charge or credit operations.
Question 182. Aggregate amortized analysis?
- Only considers one worst-case step
- Bounds total sequence cost and divides by operation count
- Uses an input probability distribution necessarily
- Counts CPU registers
Show correct answer and explanation
Correct answer: B. Bounds total sequence cost and divides by operation count
Sequence-level cost yields amortized per-operation bound.
Question 183. Dynamic-array append amortized cost with geometric growth?
- O(n) amortized
- O(n squared)
- O(1)
- O(log n) per append necessarily
Show correct answer and explanation
Correct answer: C. O(1)
Occasional resizing is spread over many cheap appends.
Question 184. A single dynamic-array append that triggers resizing can cost?
- Theta(1) necessarily
- Theta(log log n)
- Theta(n squared)
- Theta(n)
Show correct answer and explanation
Correct answer: D. Theta(n)
Copying n existing elements costs linear time.
Question 185. Banker’s accounting method in amortized analysis?
- Stores credits from cheap operations for future expensive ones
- Uses actual bank currency
- Only works on randomized algorithms
- Cannot analyze arrays
Show correct answer and explanation
Correct answer: A. Stores credits from cheap operations for future expensive ones
Credits pay later costs.
Question 186. P is the class of decision problems?
- Requiring exponential time by definition
- Solvable in polynomial time by a deterministic algorithm
- Verifiable only with quantum devices
- Unsatisfiable problems only
Show correct answer and explanation
Correct answer: B. Solvable in polynomial time by a deterministic algorithm
P formalizes efficient deterministic decidability.
Question 187. NP consists of decision problems?
- With no algorithms whatsoever
- Always unsolvable
- With polynomial-time verifiable yes-certificates
- Always exponential-time complete problems
Show correct answer and explanation
Correct answer: C. With polynomial-time verifiable yes-certificates
A verifier checks a candidate witness efficiently.
Question 188. Is every problem in P also in NP?
- No
- Only when inputs are graphs
- Only with randomized algorithms
- Yes
Show correct answer and explanation
Correct answer: D. Yes
A polynomial-time solver also permits polynomial-time verification.
Question 189. NP-hard means?
- At least as hard as every NP problem under a specified polynomial-time reduction
- Necessarily in NP
- Necessarily a decision problem
- Always undecidable
Show correct answer and explanation
Correct answer: A. At least as hard as every NP problem under a specified polynomial-time reduction
NP-hardness uses reductions from all NP problems.
Question 190. NP-complete means?
- Only in P
- In NP and NP-hard
- Only NP-hard outside NP
- Undecidable
Show correct answer and explanation
Correct answer: B. In NP and NP-hard
Both membership in NP and NP-hardness are required.
Question 191. Which is a classic NP-complete decision problem?
- Binary search on a sorted array
- BFS reachability
- Boolean satisfiability SAT
- Merging two sorted arrays
Show correct answer and explanation
Correct answer: C. Boolean satisfiability SAT
SAT was the first problem shown NP-complete.
Question 192. What is a polynomial-time reduction used for?
- Reducing input length to one bit always
- Finding shortest paths only
- Encrypting data
- Transforming one problem into another while preserving decision answers efficiently
Show correct answer and explanation
Correct answer: D. Transforming one problem into another while preserving decision answers efficiently
Reductions transfer computational hardness.
Question 193. If an NP-complete problem has a deterministic polynomial-time algorithm then?
- P equals NP
- P differs from NP
- All problems become undecidable
- Only sorting gets faster
Show correct answer and explanation
Correct answer: A. P equals NP
A polynomial algorithm for one NP-complete problem yields polynomial algorithms for all NP problems.
Question 194. Has P versus NP been resolved?
- Yes P equals NP
- No
- Yes P differs from NP
- Only for graphs
Show correct answer and explanation
Correct answer: B. No
The P versus NP question remains open.
Question 195. Which is a known polynomial-time problem?
- General traveling-salesperson optimization
- General Boolean SAT
- Minimum spanning tree
- General Hamiltonian cycle decision
Show correct answer and explanation
Correct answer: C. Minimum spanning tree
MST can be solved efficiently using Prim or Kruskal.
Question 196. Which classic optimization problem seeks the shortest tour through every city returning to start?
- Topological sorting
- String prefix matching
- Graph coloring verification
- Traveling salesperson problem
Show correct answer and explanation
Correct answer: D. Traveling salesperson problem
TSP seeks a minimum-cost Hamiltonian tour.
Question 197. The decision version of TSP asks?
- Whether a tour of cost at most K exists
- For the average edge length only
- Whether the graph has any vertex
- For source code memory
Show correct answer and explanation
Correct answer: A. Whether a tour of cost at most K exists
A bound K converts optimization to a yes-no question.
Question 198. Why can worst-case exponential algorithms still be practical on some inputs?
- Exponential complexity guarantees constant runtime
- Actual instances may be small or have exploitable structure
- All NP-hard problems are easy
- Input size never matters
Show correct answer and explanation
Correct answer: B. Actual instances may be small or have exploitable structure
Worst-case bounds do not determine every instance’s runtime.
Question 199. Parameterized algorithms express cost in terms of?
- Only wall-clock seconds
- Only number of files
- Input size and a chosen structural parameter
- Only the CPU clock
Show correct answer and explanation
Correct answer: C. Input size and a chosen structural parameter
Parameterization isolates potentially small aspects of input complexity.
Question 200. A fixed-parameter tractable algorithm has running time of form?
- n raised to k necessarily
- 2 to the n for every k
- Constant for all input sizes
- f(k) times n to a constant power independent of k
Show correct answer and explanation
Correct answer: D. f(k) times n to a constant power independent of k
FPT separates parameter dependence from polynomial input dependence.
