

















































































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 of the following properties is NOT required for a procedure to be considered an algorithm? A) Finiteness B) Definiteness C) Randomness D) Effectiveness Answer: C Explanation: An algorithm must be finite, well-defined, and effective; randomness is not a required property. Question 2. In the analysis of an algorithm, the term âkey operationâ usually refers to: A) The most frequently executed line of code B) The operation that dominates the running time C) Any arithmetic operation D) The first operation performed Answer: B Explanation: The key operation is the one that determines the asymptotic running time, often the most expensive step. Question 3. Which asymptotic notation describes a lower bound that is tight for large inputs? A) O-notation B) Ω-notation C) Î-notation D) o-notation Answer: B
Explanation: Ωânotation gives a tight lower bound on growth rate for sufficiently large input sizes. Question 4. The worstâcase time complexity of binary search on a sorted array of size n is: A) O(1) B) O(log n) C) O(n) D) O(n log n) Answer: B Explanation: Binary search halves the search interval each step, leading to Î(log n) comparisons in the worst case. Question 5. In amortized analysis, the aggregate method determines the average cost per operation by: A) Analyzing only the most expensive operation B) Summing the total cost of a sequence of operations and dividing by the number of operations C) Ignoring occasional costly operations D) Using probabilistic arguments Answer: B Explanation: The aggregate method computes total cost over a sequence and averages it, giving the amortized cost per operation. Question 6. The recurrence T(n) = 2 T(n/2) + n solves to which of the following asymptotic bounds? A) O(log n) B) O(n)
C) Dynamic programming D) Backtracking Answer: C Explanation: Dynamic programming relies on optimal substructure, where optimal solutions to subâproblems combine to form an optimal overall solution. Question 10. Which of the following problems is known to have a polynomialâtime greedy solution? A) Traveling salesman problem B) Minimum spanning tree C) 0/1 knapsack D) Subset sum Answer: B Explanation: Both Primâs and Kruskalâs algorithms use greedy choices to construct a minimum spanning tree in polynomial time. Question 11. In the 0/1 knapsack problem, the DP table entry DP[i][w] typically stores: A) Maximum profit using first i items with capacity w B) Minimum weight needed to achieve profit w using i items C) Number of ways to fill capacity w with i items D) True/False indicating feasibility Answer: A Explanation: DP[i][w] records the best profit achievable with the first i items and a knapsack capacity of w. Question 12. The FloydâWarshall algorithm computes:
A) Shortest paths from a source to all vertices B) Shortest paths between all pairs of vertices C) Minimum spanning tree of a graph D) Maximum flow in a network Answer: B Explanation: FloydâWarshall is an allâpairs shortestâpath algorithm using dynamic programming. Question 13. Which recurrence corresponds to the running time of the naive recursive Fibonacci algorithm? A) T(n) = T(nâ1) + T(nâ2) + O(1) B) T(n) = 2 T(n/2) + O(1) C) T(n) = T(nâ1) + O(1) D) T(n) = T(n/3) + O(log n) Answer: A Explanation: Each call to Fib(n) spawns two recursive calls: Fib(nâ1) and Fib(nâ2), plus constant work. Question 14. In a binary heap, the height h of a heap containing n elements is: A) O(log n) B) O(n) C) O(ân) D) O(1) Answer: A Explanation: A binary heap is a complete binary tree, whose height is âlogâ nâ.
Explanation: A DAGâs lack of cycles permits ordering vertices such that every edge goes from earlier to later vertex. Question 18. Which of the following statements about Dijkstraâs algorithm is FALSE? A) It works with negative edge weights B) It uses a priority queue to select the next vertex C) It computes shortest paths from a single source D) It runs in O((V+E) log V) with a binary heap Answer: A Explanation: Dijkstraâs algorithm assumes all edge weights are nonânegative; otherwise it may produce incorrect results. Question 19. The BellmanâFord algorithm can detect: A) Positive weight cycles B) Negative weight cycles reachable from the source C) Only acyclic graphs D) Minimum spanning trees Answer: B Explanation: After |V|â1 relaxations, an extra pass that still relaxes an edge indicates a reachable negativeâweight cycle. Question 20. In the context of NPâcompleteness, a polynomialâtime reduction from problem A to problem B implies: A) A is easier than B B) B is at least as hard as A C) Both problems belong to P
D) A can be solved in logarithmic time Answer: B Explanation: If A â€_p B, any polynomial algorithm for B yields a polynomial algorithm for A, so B is at least as hard as A. Question 21. Which of the following problems is known to be NPâcomplete? A) Minimum spanning tree B) Shortest path with nonânegative weights C) Hamiltonian cycle D) Binary search Answer: C Explanation: Determining whether a graph contains a Hamiltonian cycle is a classic NPâcomplete problem. Question 22. An approximation algorithm for the vertexâcover problem with ratio 2 guarantees: A) The algorithm always finds the optimal cover B) The size of the returned cover is at most twice the optimal size C) The algorithm runs in exponential time D) The cover size is within an additive constant of the optimum Answer: B Explanation: A 2âapproximation means the algorithmâs output is bounded by 2 · OPT. Question 23. In backtracking, the âbranch and boundâ technique differs primarily by: A) Storing all previously visited states B) Using a heuristic to prune branches that cannot lead to better solutions
Answer: B Explanation: Property that no path can be more than twice as long as any other ensures height †2 · logâ(n+1). Question 27. The time complexity of building a binary heap from an unordered array of n elements using the âheapifyâ method is: A) O(n log n) B) O(n) C) O(log n) D) O(nÂČ) Answer: B Explanation: The bottomâup heap construction runs in linear time because lower levels require fewer perânode operations. Question 28. Which of the following sorting algorithms is NOT stable in its standard implementation? A) Merge sort B) Insertion sort C) Quick sort D) Counting sort Answer: C Explanation: Quick sortâs partitioning can reorder equal keys, making it unstable unless specifically modified.
Question 29. In the context of graph representations, an adjacency list is more spaceâefficient than an adjacency matrix when: A) The graph is dense B) The graph is sparse C) The graph has selfâloops D) The graph is directed Answer: B Explanation: Sparse graphs have far fewer edges than VÂČ, so adjacency lists store only existing edges, using O(V+E) space. Question 30. The master theorem case where f(n) = Î(n^{log_b a} · log^k n) yields T(n) = Î(n^{log_b a} · log^{k+1} n). This corresponds to which of the following parameter values? A) a > b^c, k = 0 B) a = b^c, k â„ 0 C) a < b^c, k = â 1 D) a = b^c, k = â 1 Answer: B Explanation: When f(n) matches n^{log_b a} up to a polylog factor (k â„ 0), the solution gains an extra log factor. Question 31. Which algorithm uses a âdivideâandâconquerâ approach to multiply two matrices in O(n^{logâ 7}) time? A) Strassenâs algorithm B) CoppersmithâWinograd algorithm C) Standard cubic multiplication D) Karatsubaâs algorithm
C) Item i placed at the beginning vs. end of the knapsack D) Item i duplicated vs. unique Answer: A Explanation: The recurrence chooses the better of excluding the item or including it (if weight permits). Question 35. Which of the following problems can be solved optimally by a greedy algorithm but not by a simple DP formulation due to lack of overlapping subâproblems? A) Longest common subsequence B) Fractional knapsack C) Matrix chain multiplication D) 0/1 knapsack Answer: B Explanation: Fractional knapsack has optimal greedy solution; DP is unnecessary because subâproblems do not overlap. Question 36. In a BFS traversal of an undirected graph, the first time a vertex v is discovered, the discovered edge (u, v) is guaranteed to be: A) Part of a shortest path from the source to v B) Part of a minimum spanning tree C) A back edge D) A cross edge Answer: A Explanation: BFS discovers vertices in order of increasing distance; the edge used to discover v lies on a shortestâpath tree.
Question 37. The time complexity of the DFS algorithm implemented with adjacency lists is: A) O(V + E) B) O(VÂČ) C) O(E log V) D) O(V log V) Answer: A Explanation: DFS visits each vertex and explores each edge once, giving linear time in the size of the graph. Question 38. In a directed graph, a âstrongly connected componentâ (SCC) is defined as: A) A maximal set of vertices where each vertex is reachable from every other vertex via directed paths B) Any cycle in the graph C) A set of vertices with the same indegree D) A component that contains no directed edges Answer: A Explanation: SCCs are maximal subsets where mutual reachability via directed edges holds. Question 39. The âcut propertyâ used in Kruskalâs algorithm states that: A) Adding the smallest edge that connects two different trees never creates a cycle B) The lightest edge crossing any cut belongs to some minimum spanning tree C) All edges in the MST have equal weight D) The total weight of a cut equals the weight of the MST Answer: B
D) It has a known polynomialâtime approximation scheme Answer: B Explanation: NPâhard problems are at least as hard as any problem in NP; any NP problem reduces to them. Question 43. The âbranch and boundâ method for the traveling salesman problem typically uses which of the following to compute lower bounds? A) Minimum spanning tree of remaining cities B) Maximum flow in the graph C) Shortest path tree from the start city D) Depthâfirst search tree cost Answer: A Explanation: A common lower bound is the cost of a minimum spanning tree on the unvisited vertices plus the cheapest edges connecting to the current path. Question 44. In a hash table that uses separate chaining, the expected length of a chain is: A) O(1) if load factor α = n/m is constant B) O(n) regardless of load factor C) O(log n) D) O(m) where m is the number of buckets Answer: A Explanation: With a constant load factor α = n/m, the average chain length is α, i.e., Î(1). Question 45. The âdivideâ step in divideâandâconquer algorithms typically: A) Reduces the problem size by a constant amount each time B) Splits the problem into a fixed number of subâproblems of roughly equal size
C) Increases the problem size to simplify recursion D) Converts the problem into a graph traversal Answer: B Explanation: Divideâandâconquer partitions the input into a constant number of subâproblems whose sizes are fractions of the original. Question 46. Which of the following sorting algorithms has the best worstâcase time complexity? A) Quick sort B) Merge sort C) Bubble sort D) Insertion sort Answer: B Explanation: Merge sort guarantees Î(n log n) worstâcase time, while quick sort can degrade to Î(nÂČ). Question 47. In the context of the Master Theorem, the case where f(n) = O(n^{log_b a â Δ}) for some Δ > 0 leads to which solution form? A) Î(n^{log_b a}) B) Î(f(n)) C) Î(n^{log_b a} · log n) D) Î(n^{log_b a + Δ}) Answer: A Explanation: When f(n) is polynomially smaller than n^{log_b a}, the solution is dominated by the recursive term, yielding Î(n^{log_b a}).
Explanation: On average, the target is found after examining half the elements, leading to Î(n) expected time. Question 51. The âbalance factorâ in an AVL tree for a node is defined as: A) Height of left subtree minus height of right subtree B) Number of nodes in left subtree minus right subtree C) Depth of node minus its height D) Difference between key values of left and right children Answer: A Explanation: AVL trees maintain |balance factor| †1 to ensure logarithmic height. Question 52. In the context of graph algorithms, a ârelaxationâ operation on an edge (u, v) performs: A) Updating the distance to v if a shorter path through u is found B) Removing the edge from the graph C) Adding a new vertex between u and v D) Swapping the direction of the edge Answer: A Explanation: Relaxation attempts to improve the current best known distance to a vertex by using a candidate edge. Question 53. Which of the following sorting algorithms is most suitable for sorting data that fits in external memory (disk) and requires minimal random access? A) Quick sort B) Merge sort (external) C) Heap sort
D) Insertion sort Answer: B Explanation: External merge sort uses sequential reads/writes, ideal for diskâbased data. Question 54. In the context of approximation algorithms, a PTAS (PolynomialâTime Approximation Scheme) provides: A) A solution within a factor (1 + Δ) of optimal for any Δ > 0, in polynomial time for fixed Δ B) An exact solution in polynomial time C) A constantâfactor approximation independent of Δ D) A randomized solution with expected optimality Answer: A Explanation: PTAS yields arbitrarily close approximations, with runtime polynomial for each fixed Δ. Question 55. The âcritical pathâ in a project scheduling graph (DAG) corresponds to: A) The longest path from start to finish, determining minimum project duration B) The path with the most edges C) The shortest path from source to sink D) Any path that includes a cycle Answer: A Explanation: The critical path length equals the projectâs makespan; any delay on it extends the overall schedule. Question 56. In a binary search tree (BST), the inorder traversal visits nodes in: A) Ascending order of keys B) Descending order of keys