Docsity

[CCDAP] CodeChef Certified Data Structure Algorithms Programme Certification Exam Preparat, Exams of Technology

Toggle sidebar
bg1
[CCDAP] CodeChef Certified Data Structure
Algorithms Programme Certification Exam
Preparation
**Question 1.** Which of the following best describes the meaning of Θ‑notation in algorithm
analysis?
A) Upper bound on running time
B) Lower bound on running time
C) Tight bound on running time
D) Average case running time
Answer: C
Explanation: Θ‑notation provides both an upper and lower asymptotic bound, indicating that
the algorithm’s running time grows at the same rate as the given function.
**Question 2.** In an array of size *n*, what is the time complexity of rotating the array left by
*k* positions using the reversal algorithm?
A) O(n log n)
B) O(k)
C) O(n)
D) O(1)
Answer: C
Explanation: The reversal algorithm performs three linear‑time reversals, each O(n), resulting in
overall O(n) time.
**Question 3.** Which of the following statements about a circular queue implemented with
an array of size *N* is correct?
A) The queue can hold *N + 1* elements
B) The condition `front == rear` always means the queue is empty
C) The condition `(rear + 1) % N == front` indicates the queue is full
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
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download [CCDAP] CodeChef Certified Data Structure Algorithms Programme Certification Exam Preparat and more Exams Technology in PDF only on Docsity!

Algorithms Programme Certification Exam

Preparation

Question 1. Which of the following best describes the meaning of Θ‑notation in algorithm analysis? A) Upper bound on running time B) Lower bound on running time C) Tight bound on running time D) Average case running time Answer: C Explanation: Θ‑notation provides both an upper and lower asymptotic bound, indicating that the algorithm’s running time grows at the same rate as the given function. Question 2. In an array of size n, what is the time complexity of rotating the array left by k positions using the reversal algorithm? A) O(n log n) B) O(k) C) O(n) D) O(1) Answer: C Explanation: The reversal algorithm performs three linear‑time reversals, each O(n), resulting in overall O(n) time. Question 3. Which of the following statements about a circular queue implemented with an array of size N is correct? A) The queue can hold N + 1 elements B) The condition front == rear always means the queue is empty C) The condition (rear + 1) % N == front indicates the queue is full

Algorithms Programme Certification Exam

Preparation

D) The rear index never wraps around Answer: C Explanation: In a circular queue, when the next position of rear equals front, the queue is full; this is expressed as (rear + 1) % N == front. Question 4. Which data structure allows O(1) time insertion and deletion at both ends but O(n) time random access? A) Array B) Stack C) Deque implemented with a linked list D) Binary search tree Answer: C Explanation: A linked‑list based deque supports constant‑time insert/delete at head and tail, but accessing an arbitrary index requires traversing O(n) nodes. Question 5. For a singly linked list, which of the following operations requires O(n) time in the worst case? A) Inserting a node at the head B) Deleting the head node C) Searching for a value D) Accessing the tail pointer (if maintained) Answer: C Explanation: Searching may need to traverse the entire list, leading to O(n) time, whereas head operations are O(1).

Algorithms Programme Certification Exam

Preparation

D) O(m log n) Answer: B Explanation: The naïve algorithm may compare the pattern of length m at each of the n – m + 1 positions, yielding O(n·m) time. Question 9. Which of the following statements about the Euclidean algorithm for GCD is true? A) Its worst‑case time is O(log n) where n is the larger input B) It requires O(n) recursive calls for inputs of size n C) It only works for positive integers D) It cannot be implemented iteratively Answer: A Explanation: The Euclidean algorithm runs in O(log min(a,b)) time because each step reduces the magnitude of the numbers by at least a factor of two. Question 10. Which of the following greedy strategies correctly solves the activity‑selection problem (maximizing number of non‑overlapping intervals)? A) Choose the activity with the earliest start time B) Choose the activity with the shortest duration C) Choose the activity with the earliest finish time that is compatible D) Choose the activity with the latest start time Answer: C Explanation: Selecting the compatible activity that finishes earliest leaves maximal room for subsequent activities, yielding an optimal solution.

Algorithms Programme Certification Exam

Preparation

Question 11. In a binary search tree (BST), which operation has worst‑case time O(n) and why? A) Inserting a node B) Deleting a leaf node C) Searching for a key D) All of the above, when the tree becomes a degenerate linked list Answer: D Explanation: If insertions occur in sorted order, the BST degenerates into a linear chain, making insert, delete, and search each O(n) in the worst case. Question 12. Which tree traversal yields the nodes of a binary search tree in sorted order? A) Pre‑order B) In‑order C) Post‑order D) Level‑order Answer: B Explanation: In‑order traversal visits left subtree, root, then right subtree; for a BST this produces keys in non‑decreasing order. Question 13. Which of the following statements about heap‑sort’s space complexity is correct? A) It requires O(n) auxiliary space for the heap array B) It can be performed in‑place using the input array itself C) It needs a separate priority‑queue data structure D) It cannot sort in descending order

Algorithms Programme Certification Exam

Preparation

Question 16. In depth‑first search (DFS) on a directed graph, which of the following can be detected by examining the vertex colors (white, gray, black) during traversal? A) Presence of a Hamiltonian cycle B) Existence of a back edge indicating a cycle C) Shortest path lengths from the source D) Minimum spanning tree edges Answer: B Explanation: Encountering a gray vertex during DFS indicates a back edge, which implies a cycle in a directed graph. Question 17. Which of the following statements about Dijkstra’s algorithm is false? A) It works with non‑negative edge weights B) It can be implemented with a binary heap to achieve O((V + E) log V) time C) It correctly computes shortest paths in graphs containing negative cycles D) It maintains a priority queue of tentative distances Answer: C Explanation: Dijkstra’s algorithm assumes all edge weights are non‑negative; negative cycles invalidate its correctness. Question 18. The Bellman‑Ford algorithm can be used to detect which of the following? A) Positive weight cycles B) Negative weight cycles reachable from the source C) Only acyclic graphs D) Minimum spanning trees

Algorithms Programme Certification Exam

Preparation

Answer: B Explanation: After |V| – 1 relaxations, an additional pass that still relaxes an edge indicates a reachable negative‑weight cycle. Question 19. In dynamic programming, which of the following best describes “memoization”? A) Bottom‑up filling of a DP table B) Top‑down recursion with caching of computed results C) Using a sliding window to reduce space D) Transforming a recursive solution into an iterative one Answer: B Explanation: Memoization stores results of subproblems during a top‑down recursive execution to avoid recomputation. Question 20. Which of the following classic DP problems has a state transition of dp[i][j] = dp[i‑1][j] + dp[i‑1][j‑1]? A) Longest Increasing Subsequence B) 0/1 Knapsack C) Binomial coefficient (Pascal’s triangle) D) Edit distance Answer: C Explanation: The recurrence computes C(i, j) = C(i‑1, j) + C(i‑1, j‑1), exactly the rule for Pascal’s triangle. Question 21. Which bit manipulation trick isolates the lowest set bit of an integer x?

Algorithms Programme Certification Exam

Preparation

Explanation: Prefix sum at r includes all elements up to r, so subtracting the prefix before l (P[l‑1]) yields the desired range sum. Question 24. Which two‑pointer technique is most appropriate for finding all pairs in a sorted array that sum to a target value S? A) Increment both pointers simultaneously B) Move the left pointer right while moving the right pointer left based on comparison with S C) Use a stack to store visited elements D) Randomly shuffle the array before scanning Answer: B Explanation: Starting with pointers at both ends, adjust them inward depending on whether the current sum is less than or greater than S. Question 25. What is the main advantage of using a sliding window over a naïve O(n²) nested‑loop approach for problems like “maximum sum subarray of size k”? A) It reduces time complexity to O(log n) B) It reduces time complexity to O(n) while using O(1) extra space C) It eliminates the need for any loops D) It works only for arrays with negative numbers Answer: B Explanation: The sliding window maintains a running sum, updating it in constant time as the window moves, achieving linear time and constant extra space. Question 26. In modular arithmetic, which of the following statements is true for a prime modulus p and an integer a not divisible by p?

Algorithms Programme Certification Exam

Preparation

A) a^(p‑1) ≡ 0 (mod p) B) a^(p‑1) ≡ 1 (mod p) (Fermat’s Little Theorem) C) a^(p) ≡ a (mod p) only when a is even D) No modular inverse exists for a Answer: B Explanation: Fermat’s Little Theorem states that for prime p, a^(p‑1) ≡ 1 (mod p) when a and p are coprime. Question 27. Which of the following formulas correctly computes the modular inverse of a modulo m using the Extended Euclidean Algorithm? A) inv = a % m B) inv = (a^(m‑2)) % m (only when m is prime) C) inv = x where ax + my = gcd(a,m) = 1 D) inv = (a + m) % m Answer: C Explanation: The extended Euclidean algorithm finds integers x and y such that ax + my = gcd(a,m). When gcd is 1, x is the modular inverse of a modulo m. Question 28. In combinatorics, which of the following expressions gives the number of ways to choose k items from n distinct items without regard to order? A) n! / (k! * (n‑k)!) B) n! / k! C) k! * (n‑k)! D) n^k Answer: A

Algorithms Programme Certification Exam

Preparation

B) O(L)

C) O(log L) D) O(1) Answer: B Explanation: Each character leads to a single child traversal; with constant alphabet, insertion costs linear in the string length. Question 32. Which of the following queries can be answered in O(1) time after building a 2 ‑D prefix‑sum matrix? A) Sum of any rectangular sub‑matrix B) Minimum element in a sub‑matrix C) Maximum element in a sub‑matrix D) Count of distinct values in a sub‑matrix Answer: A Explanation: 2‑D prefix sums let us compute the sum of any axis‑aligned rectangle using four lookups and constant‑time arithmetic. Question 33. Which of the following graph algorithms can be used to find a Minimum Spanning Tree (MST) in a weighted undirected graph? A) Dijkstra’s algorithm B) Prim’s algorithm C) Floyd‑Warshall algorithm D) Topological sort Answer: B

Algorithms Programme Certification Exam

Preparation

Explanation: Prim’s algorithm grows an MST by repeatedly adding the cheapest edge that connects a visited vertex to an unvisited vertex. Question 34. In Kruskal’s algorithm, which data structure is essential for efficiently detecting cycles while adding edges? A) Stack B) Queue C) Disjoint Set Union (Union‑Find) D) Priority queue only Answer: C Explanation: Union‑Find maintains connected components; before adding an edge, it checks whether its endpoints belong to the same set (cycle detection). Question 35. Which of the following statements about the Ford‑Fulkerson method for maximum flow is true? A) It always runs in polynomial time regardless of capacities B) Its running time depends on the choice of augmenting paths and may be exponential C) It requires the graph to be acyclic D) It can only handle unit capacities Answer: B Explanation: The basic Ford‑Fulkerson algorithm’s complexity depends on the augmenting path selection; with irrational capacities it may not terminate, and with integer capacities it can be O(E · max flow). Question 36. In a flow network, the Max‑Flow Min‑Cut theorem states that:

Algorithms Programme Certification Exam

Preparation

Answer: C Explanation: The Z‑algorithm constructs the Z‑array (length of longest substring starting at i that matches the prefix) in O(m + n) time, analogous to KMP’s failure function. Question 39. Which of the following data structures is best suited for answering static Range Minimum Queries (RMQ) in O(1) time after O(n log n) preprocessing? A) Segment tree B) Fenwick tree C) Sparse table D) Binary indexed tree with lazy propagation Answer: C Explanation: A sparse table stores precomputed minima for intervals of length 2^k, allowing O(1) RMQ via two overlapping intervals. Question 40. In the context of computational geometry, which algorithm computes the convex hull of a set of points in O(n log n) time? A) Graham scan B) Dijkstra’s algorithm C) Kruskal’s algorithm D) Floyd‑Warshall algorithm Answer: A Explanation: Graham scan sorts points by polar angle and then scans to construct the hull, achieving O(n log n) time.

Algorithms Programme Certification Exam

Preparation

Question 41. Which of the following statements about the Chinese Remainder Theorem (CRT) is correct? A) It provides a solution only when moduli are pairwise prime B) It guarantees a unique solution modulo the product of pairwise coprime moduli C) It cannot be used for more than two congruences D) It always produces the smallest non‑negative solution regardless of modulus relationships Answer: B Explanation: CRT states that a system of congruences with pairwise coprime moduli has a unique solution modulo the product of the moduli. Question 42. In a 0/1 knapsack problem solved by dynamic programming, the time complexity is O(n · W) where W is: A) Number of items B) Maximum weight capacity C) Sum of values of all items D) Logarithm of the capacity Answer: B Explanation: The classic DP builds a table of size (n + 1) × (W + 1), leading to O(n · W) time. Question 43. Which of the following DP optimization techniques is applicable when the recurrence has the form dp[i] = min_{j < i} (dp[j] + m*j + b) and the slopes m are monotonic? A) Convex Hull Trick B) Bitmask DP C) Divide and Conquer DP

Algorithms Programme Certification Exam

Preparation

Question 46. Which of the following statements about the Euler’s Totient function φ(n) is correct? A) φ(n) counts the number of prime factors of n B) φ(n) = n – 1 for all n C) φ(n) is multiplicative for coprime arguments: φ(ab) = φ(a)·φ(b) when gcd(a,b)= D) φ(n) is always even for n > 2 Answer: C Explanation: φ is multiplicative over coprime integers; the formula φ(p^k) = p^k – p^{k‑1} leads to the general property. Question 47. In a binary indexed tree (Fenwick), which operation is used to compute the prefix sum up to index i? A) Repeatedly add tree[i] and set i = i & (i - 1) B) Repeatedly add tree[i] and set i = i + (i & - i) C) Repeatedly subtract tree[i] and set i = i - (i & - i) D) Use recursion on child nodes Answer: A Explanation: The query operation moves the index downward by clearing the least‑significant set bit: i = i & (i - 1) while accumulating tree[i]. Question 48. Which of the following is a correct description of the “centroid decomposition” of a tree? A) Splitting the tree into two equal halves by cutting the root edge B) Recursively removing the centroid (node whose removal leaves subtrees of size ≤ n/2) to build a decomposition tree

Algorithms Programme Certification Exam

Preparation

C) Converting the tree into a binary search tree by re‑ordering nodes D) Flattening the tree into an array using Euler tour technique Answer: B Explanation: Centroid decomposition repeatedly selects a centroid, removes it, and processes each component recursively, yielding a decomposition useful for certain queries. Question 49. Which of the following is true about the suffix array of a string of length n? A) It can be built in O(n²) time using naïve sorting B) It stores all suffixes in lexicographic order and can be built in O(n log n) time with efficient algorithms C) It requires O(n²) space D) It cannot be used for pattern matching Answer: B Explanation: Efficient suffix‑array construction (e.g., SA‑IS, doubling) runs in O(n log n) time and stores n indices, enabling binary search for pattern matching. Question 50. In the KMP (Knuth‑Morris‑Pratt) algorithm, the “failure function” (also called LPS array) for a pattern of length m can be computed in: A) O(m²) time B) O(m log m) time C) O(m) time D) O(1) time Answer: C Explanation: The LPS (Longest Proper Prefix which is also a suffix) array is built in linear time by scanning the pattern once.