







































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!








































Question 1. Which asymptotic notation describes a lower bound that is not tight for a function f(n)? A) O(f(n)) B) Ω(f(n)) C) Θ(f(n)) D) o(f(n)) Answer: D Explanation: Little‑o denotes a strict lower bound, meaning f(n) grows faster than the bound; it is not tight. Question 2. If T(n) = 3T(n/4) + n, what is T(n) in Θ‑notation according to the Master Theorem? A) Θ(n) B) Θ(n log n) C) Θ(n^{log₄3}) D) Θ(n^{2}) Answer: C Explanation: a = 3, b = 4, f(n)=n. Since n^{log_b a}=n^{log₄3} ≈ n^{0.79} and f(n) = Ω(n^{log_b a+ε}) with ε≈0.21, case 3 applies, giving Θ(f(n)) = Θ(n). Question 3. Which of the following series sums to Θ(n²)? A) ∑{i=1}^{n} i B) ∑{i=1}^{n} i² C) ∑{i=1}^{n} 2^{i} D) ∑{i=1}^{n} 1/i Answer: B Explanation: The sum of squares ∑i² = n(n+1)(2n+1)/6 = Θ(n³), but the question asks for Θ(n²); the correct series is ∑i = n(n+1)/2 = Θ(n²). Hence the answer is A. (Correction: The intended answer is A; the options were mis‑ordered. The correct series that yields Θ(n²) is ∑i, option A.) Question 4. In a proof by induction for the recurrence T(n)=2T(n/2)+n, which statement serves as the inductive hypothesis?
A) T(k)=k log k for all k < n B) T(k) ≤ c k log k for some constant c and all k < n C) T(k) = 2T(k/2)+k for all k < n D) T(k) ≥ k² for all k < n Answer: B Explanation: To prove an upper bound, we assume the bound holds for smaller inputs (inductive hypothesis) and then show it holds for n. Question 5. Which loop invariant correctly proves that insertion sort maintains a sorted prefix? A) After i‑th iteration, the first i elements are in non‑decreasing order. B) After i‑th iteration, the array is fully sorted. C) After i‑th iteration, the last i elements are sorted. D) After i‑th iteration, the array contains i inversions. Answer: A Explanation: Insertion sort builds a sorted prefix incrementally; the invariant states that the first i elements are sorted after each iteration. Question 6. The recurrence T(n) = T(n‑1) + 1 has solution Θ(?). A) Θ(log n) B) Θ(n) C) Θ(n log n) D) Θ(2^{n}) Answer: B Explanation: Expanding the recurrence gives T(n)=T(1)+(n‑1)·1 = Θ(n). Question 7. Which recurrence cannot be solved directly by the standard Master Theorem? A) T(n)=2T(n/2)+n B) T(n)=3T(n/3)+n log n C) T(n)=T(n‑1)+n
Explanation: The median‑of‑medians algorithm selects a pivot that guarantees a split of at least 30‑70, leading to O(n log n) worst‑case. Question 11. Which property makes heap sort an in‑place sorting algorithm? A) It uses a separate auxiliary array. B) All data is stored within the input array as a binary heap. C) It requires O(n) extra space for a priority queue. D) It builds a linked list of elements. Answer: B Explanation: Heap sort transforms the input array into a binary heap and then repeatedly extracts the maximum, all within the same array. Question 12. In counting sort, the running time is Θ(n + k). What does k represent? A) The number of distinct keys. B) The maximum key value. C) The number of buckets used. D) The average key frequency. Answer: B Explanation: k is the range of possible key values (often the maximum integer value), determining the size of the counting array. Question 13. Which condition allows radix sort to run in linear time Θ(n)? A) All keys have the same number of digits and the base is constant. B) Keys are floating‑point numbers. C) The input is already sorted. D) The algorithm uses comparison operations. Answer: A Explanation: When the number of digits d and the base b are constants, the total work is O(d·(n+b)) = Θ(n).
Question 14. In the deterministic linear‑time selection algorithm, what is the size of the groups used to guarantee linear time? A) 3 B) 5 C) 7 D) 9 Answer: B Explanation: Grouping elements into groups of 5 and taking the median of medians ensures a good enough split to achieve Θ(n) time. Question 15. Which of the following statements about the randomized select algorithm is true? A) It always runs in Θ(n) worst‑case time. B) Its expected running time is Θ(n). C) It requires O(n log n) extra space. D) It cannot be used to find the median. Answer: B Explanation: Randomized select has expected linear time, though its worst case can be quadratic. Question 16. Which hash‑function method is most resistant to clustering when the table size is a power of two? A) Division method with prime modulus B) Multiplication method C) Mid‑square method D) Universal hashing with random a,b Answer: B Explanation: The multiplication method works well even when the table size is a power of two because it multiplies by a constant and extracts high‑order bits, reducing clustering. Question 17. In open addressing with linear probing, what is the expected number of probes for an unsuccessful search when the load factor α < 1?
B) Left rotation C) Left‑right rotation D) Right‑left rotation Answer: A Explanation: A left‑left imbalance is corrected by a single right rotation at the unbalanced node. Question 21. In a red‑black tree, what is the maximum height relative to the number of nodes n? A) log₂ n B) 2 log₂ n C) log₂ n + 1 D) n / 2 Answer: B Explanation: A red‑black tree with n nodes has height at most 2 log₂ (n + 1). Question 22. Which property does a B‑tree of order m guarantee? A) Each node has exactly m children. B) All leaves are at the same depth and each internal node has between ⌈m/2⌉ and m children. C) The tree is always perfectly balanced. D) Each node stores at most m‑1 keys and exactly m children. Answer: B Explanation: In a B‑tree of order m, each internal node (except possibly the root) has at least ⌈m/2⌉ and at most m children; all leaves lie on the same level. Question 23. Which augmentation to a binary search tree enables order‑statistics (select k‑th smallest) in O(log n) time? A) Storing subtree heights. B) Storing the number of nodes in each subtree. C) Storing parent pointers. D) Storing the sum of keys.
Answer: B Explanation: Keeping size fields (the count of nodes in each subtree) allows us to walk down the tree to locate the k‑th smallest element in logarithmic time. Question 24. In the potential method of amortized analysis, what does the potential function Φ represent? A) The actual runtime of the algorithm. B) The amount of “stored work” that can be used to pay for future operations. C) The worst‑case time of a single operation. D) The number of recursive calls. Answer: B Explanation: Φ maps a data‑structure state to a non‑negative number representing prepaid work; amortized cost = actual cost + ΔΦ. Question 25. Which of the following problems exhibits optimal substructure? A) Finding a Hamiltonian cycle in a graph. B Traveling Salesperson Problem (exact). C Longest Common Subsequence. D Graph coloring. Answer: C Explanation: LCS can be solved by DP because an optimal solution contains optimal solutions to its subproblems. Question 26. In the 0/1 knapsack problem, why does the greedy algorithm that picks items by highest value/weight ratio fail? A) Because the problem is NP‑complete. B) Because items must be taken fractionally. C) Because the ratio does not guarantee optimality for the 0/1 version. D) Because the algorithm runs in exponential time. Answer: C
Question 30. Which of the following statements about matroids is true? A) Every graph forms a matroid under edge inclusion. B) Matroids capture the exact conditions under which a greedy algorithm yields an optimal solution. C) Matroids are only applicable to linear algebra. D) The greedy algorithm fails on matroids. Answer: B Explanation: A set system is a matroid iff the greedy algorithm is guaranteed to produce an optimal solution for any weight function. Question 31. Which edge classification appears only in depth‑first search of a directed graph? A) Tree edge B) Back edge C) Forward edge D) All of the above Answer: D Explanation: In DFS of a directed graph, edges are classified as tree, back, forward, or cross edges. Question 32. In Kosaraju’s algorithm for strongly connected components, what is the purpose of the second DFS on the transpose graph? A) To compute topological order. B) To discover SCCs in reverse finishing‑time order. C) To find bridges. D) To detect cycles. Answer: B Explanation: The second DFS processes vertices in decreasing order of finishing times from the first DFS, ensuring each DFS tree corresponds to one SCC. Question 33. Which data structure enables Kruskal’s algorithm to run in near‑linear time? A) Binary heap
B) Fibonacci heap C) Disjoint Set Union with union by rank and path compression D) Adjacency matrix Answer: C Explanation: DSU operations (find/union) with union by rank and path compression run in almost O(α(n)) time, making Kruskal’s overall complexity O(m α(n)). Question 34. In Prim’s algorithm implemented with a binary heap, what is the overall time complexity for a graph with V vertices and E edges? A) O(V log V) B) O(E log V) C) O(V + E) D) O(E + V log V) Answer: B Explanation: Each edge insertion/decrease‑key costs O(log V); total O(E log V). The initial heap of vertices adds O(V log V), dominated by O(E log V). Question 35. Which of the following statements about Dijkstra’s algorithm is false? A) It works only with non‑negative edge weights. B) It can be implemented with a Fibonacci heap to achieve O(E + V log V) time. C) It can detect negative‑weight cycles. D) It computes shortest‑path distances from a single source. Answer: C Explanation: Dijkstra’s algorithm cannot handle negative weights and therefore cannot detect negative‑weight cycles. Question 36. The Bellman‑Ford algorithm can be used to: A) Find the maximum flow in a network. B) Detect a negative‑weight cycle reachable from the source. C) Compute all‑pairs shortest paths in O(V³).
Explanation: The max‑flow min‑cut theorem states that the value of the maximum flow equals the capacity of the minimum s‑t cut. Question 40. In the Edmonds‑Karp implementation of Ford‑Fulkerson, which augmenting path selection rule is used? A) Random path. B) Shortest‑path (fewest edges) via BFS. C) Path with maximum residual capacity. D) Depth‑first search path. Answer: B Explanation: Edmonds‑Karp chooses the augmenting path with the fewest edges, found by BFS, guaranteeing O(V E²) time. Question 41. Which of the following problems is known to be NP‑complete? A) Finding a spanning tree of minimum weight. B) Longest common subsequence. C) Subset sum. D) Topological sorting. Answer: C Explanation: Subset sum is a classic NP‑complete problem; the others are either polynomial‑time solvable or not decision problems. Question 42. The Cook‑Levin theorem establishes that: A) P = NP. B) SAT is NP‑complete. C) All problems in NP can be reduced to Turing machine halting. D) Graph isomorphism is NP‑complete. Answer: B Explanation: Cook‑Levin proved that the Boolean satisfiability problem (SAT) is NP‑complete, the first such problem.
Question 43. To prove that a problem X is NP‑hard, one typically: A) Shows X ∈ NP and X reduces to a known NP‑complete problem. B Shows a known NP‑complete problem reduces to X in polynomial time. C Shows X can be solved in exponential time. D Shows X is undecidable. Answer: B Explanation: Demonstrating that a known NP‑complete problem polynomial‑time reduces to X proves X is at least as hard as any NP problem, i.e., NP‑hard. Question 44. Which approximation algorithm yields a factor‑2 guarantee for the Vertex Cover problem? A) Greedy edge‑picking algorithm. B) Linear programming relaxation with rounding. C) Randomized rounding. D) All of the above. Answer: D Explanation: Both the simple greedy picking both endpoints of an uncovered edge and the LP‑based rounding achieve a 2‑approximation. Question 45. In a PTAS (Polynomial‑time Approximation Scheme) for a problem, the running time is: A) Polynomial in both input size and 1/ε. B) Polynomial in input size but possibly exponential in 1/ε. C) Exponential in input size. D) Constant for any ε. Answer: B Explanation: A PTAS runs in time O(n^{f(1/ε)}) where the exponent may depend on 1/ε, making it polynomial for fixed ε but potentially exponential as ε → 0.
A) n log n / p B) log p C) Both are equal. D) Neither; the algorithm becomes sequential. Answer: A Explanation: Substituting p = n / log n gives n log n / p = log² n, while log p = log n – log log n = O(log n). Thus the first term dominates. Question 50. The KMP string‑matching algorithm preprocesses the pattern to compute which auxiliary array? A) Failure (prefix) function. B) Suffix array. C) Z‑array. D) Hash table of substrings. Answer: A Explanation: KMP builds the prefix (also called failure) function that tells how far to shift the pattern after a mismatch. Question 51. In Rabin‑Karp algorithm, the rolling hash is used to achieve which average‑case time complexity for searching a pattern of length m in a text of length n? A) Θ(n m) B) Θ(n + m) C) Θ(n log m) D) Θ(n m log n) Answer: B Explanation: Computing the initial hash takes O(m), then each slide updates the hash in O(1); total average time is O(n + m). Question 52. Which of the following is a necessary condition for a greedy algorithm to be optimal for a given optimization problem? A) The problem must be NP‑complete.
B) The greedy‑choice property and optimal‑substructure must hold. C) All subproblems must be independent. D) The solution space must be continuous. Answer: B Explanation: Greedy optimality requires that a locally optimal (greedy) choice can be extended to a globally optimal solution and that optimal substructure exists. Question 53. In the context of amortized analysis, which method directly assigns a “credit” to each operation? A) Aggregate method B) Accounting method (Banker's) C) Potential method D) Worst‑case analysis Answer: B Explanation: The accounting method gives each operation a charge (credit) that may be stored for future expensive operations. Question 54. The splay tree performs which operation after each access? A) Red‑black recoloring. B) AVL rotations to maintain balance factor. C) Series of zig, zig‑zag, or zig‑zig rotations to move the accessed node to the root. D) No restructuring; it is a static BST. Answer: C Explanation: Splay trees “splay” the accessed node to the root using specific rotation patterns, providing amortized O(log n) access. Question 55. Which of the following statements about the Fibonacci heap’s decrease‑key operation is true? A) It runs in O(log n) worst‑case time. B) It runs in O(1) amortized time.
D) Second level only Answer: C Explanation: Each level contributes n work; there are log n levels, so total cost = n log n. Question 59. Which of the following is true about the “little‑omega” (ω) notation? A) f(n) = ω(g(n)) means f grows slower than g. B) f(n) = ω(g(n)) means for any constant c>0, eventually f(n) > c·g(n). C) ω is equivalent to O. D) ω is used only for polynomial bounds. Answer: B Explanation: Little‑omega denotes a strict lower bound: f dominates g asymptotically. Question 60. The “master theorem” fails for the recurrence T(n)=2T(n/2)+n / log n because: A) f(n) is not polynomially larger or smaller than n^{log_b a}. B) The base case is undefined. C) The recursion depth is infinite. D) It violates the regularity condition. Answer: A Explanation: The Master Theorem requires f(n) to be polynomially larger, smaller, or equal to n^{log_b a}; n/log n does not satisfy any case. Question 61. In a hash table using double hashing, the i‑th probe position is given by: A) h₁(k) + i·h₂(k) mod m B) h₁(k) ⊕ i·h₂(k) C) (i · h₁(k) + h₂(k)) mod m D) h₁(k)·h₂(k) mod i Answer: A Explanation: Double hashing computes probe sequence as (h₁(k) + i·h₂(k)) mod m, where h₂(k) is non‑zero.
Question 62. Which of the following graph representations uses O(V + E) space and allows O(1) time adjacency test? A) Adjacency matrix B) Adjacency list with hash sets per vertex C) Edge list D) Incidence matrix Answer: B Explanation: An adjacency list where each list is a hash set gives O(1) expected adjacency test while still using O(V + E) space. Question 63. In the context of NP‑completeness, what does a polynomial‑time many‑one reduction preserve? A) Solution size. B) Decision‑problem answer (yes/no). C) Running time of the algorithm. D) Space complexity. Answer: B Explanation: A many‑one reduction maps instances of problem A to instances of problem B such that the answer (yes/no) is preserved, enabling NP‑hardness proofs. Question 64. Which of the following statements about the “set cover” greedy algorithm is correct? A) It always yields the optimal solution. B) It achieves an O(log n) approximation factor, where n is the size of the universe. C) It runs in exponential time. D) It cannot be implemented without linear programming. Answer: B Explanation: The standard greedy set‑cover algorithm picks the set covering the most uncovered elements each step and achieves an Hₙ ≤ ln n + 1 approximation.