Docsity

Algorithmic Design and Techniques Practice Exam, Exams of Technology

Toggle sidebar
bg1
Algorithmic Design and Techniques Certificate
Practice Exam
**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
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59

Partial preview of the text

Download Algorithmic Design and Techniques Practice Exam and more Exams Technology in PDF only on Docsity!

Practice Exam

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

Practice Exam

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)

Practice Exam

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:

Practice Exam

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⌋.

Practice Exam

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

Practice Exam

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

Practice Exam

A) 1

B) 2

C) 3

D) 4

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.

Practice Exam

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

Practice Exam

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.

Practice Exam

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

Practice Exam

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

Practice Exam

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}).

Practice Exam

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

Practice Exam

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