








































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The PrepIQ 17COMPA4 Program Design and Data Structures B Ultimate Exam focuses on stacks, queues, trees, recursion, searching algorithms, and efficient data organization techniques.
Typology: Exams
1 / 48
This page cannot be seen from the preview
Don't miss anything!









































Question 1. Which SDLC model emphasizes delivering small, functional increments of software in short time-boxes? A) Waterfall B) Iterative C) Agile D) V-Model Answer: C Explanation: Agile focuses on iterative development with frequent, small releases. Question 2. In modular programming, a module with high internal cohesion and low coupling is considered: A) Poorly designed B) Highly reusable C) Difficult to test D) Memory intensive Answer: B Explanation: High cohesion and low coupling improve reusability and maintainability. Question 3. Which OOP principle allows a subclass to provide a specific implementation of a method declared in its superclass? A) Encapsulation B) Inheritance C) Polymorphism D) Abstraction Answer: C Explanation: Dynamic polymorphism (method overriding) lets subclasses customize behavior. Question 4. An abstract class differs from an interface in that it can:
A) Contain only abstract methods B) Provide method implementations C) Be instantiated directly D) Declare static fields only Answer: B Explanation: Abstract classes may have both abstract and concrete methods; interfaces (pre-Java 8) cannot. Question 5. The time-complexity notation Θ(f(n)) denotes: A) Upper bound only B) Lower bound only C) Both upper and lower bound D) Average case only Answer: C Explanation: Θ(f(n)) tightly bounds a function from above and below. Question 6. Which of the following best describes the worst-case time of binary search on a sorted array of size n? A) O(1) B) O(log n) C) O(n) D) O(n log n) Answer: B Explanation: Binary search halves the search space each step, giving O(log n) worst case. Question 7. In a static array, the memory for the elements is allocated: A) At compile time B) At run time on the heap
Answer: B Explanation: The “tortoise and hare” technique advances the fast pointer two steps each loop. Question 11. Which stack application is used for converting an infix expression to postfix? A) Function call management B) Undo feature in editors C) Expression evaluation D) Memory allocation tracking Answer: C Explanation: Stacks temporarily hold operators while scanning the infix expression. Question 12. A circular queue differs from a linear queue because: A) It uses linked nodes only B) It can reuse freed space without shifting elements C) It does not have a front pointer D) It stores elements in a tree structure Answer: B Explanation: When the rear reaches the array’s end, it wraps to the beginning, reusing empty slots. Question 13. Which priority-queue implementation is most efficient for repeatedly extracting the minimum element? A) Sorted array B) Unsorted array C) Binary heap D) Linked list Answer: C
Explanation: Binary heaps provide O(log n) insert and extract-min operations. Question 14. A full binary tree of height h has exactly: A) 2^h – 1 nodes B) 2^h nodes C) h · 2 nodes D) h² nodes Answer: A Explanation: A full binary tree has all levels completely filled, giving 2^h – 1 nodes. Question 15. In-order traversal of a binary search tree yields: A) Nodes in decreasing order B) Nodes in level order C) Nodes in ascending order D) Nodes in pre-order sequence Answer: C Explanation: In-order visits left subtree, root, right subtree, producing sorted keys. Question 16. The balance factor of an AVL node is defined as: A) Height(left) – Height(right) B) Height(right) – Height(left) C) Number of children – 1 D) Depth – Height Answer: A Explanation: Positive values indicate left-heavy; AVL trees keep this factor in {-1,0,1}. Question 17. After inserting a node that causes a left-right (LR) imbalance in an AVL tree, the required rotations are:
B) Adjacency list C) Edge list only D) Incidence matrix Answer: B Explanation: An adjacency list stores only existing edges, using O(V + E) space. Question 21. Breadth-First Search (BFS) on an undirected graph discovers: A) Shortest-path tree in terms of edges B) Minimum spanning tree C) Depth-first ordering D) All cycles in the graph Answer: A Explanation: BFS explores vertices level by level, yielding the minimal number of edges from the source. Question 22. Which of the following statements about Dijkstra’s algorithm is false? A) It works with negative edge weights. B) It uses a priority queue. C) It finds the shortest path from a single source. D) It relaxes edges repeatedly. Answer: A Explanation: Dijkstra’s algorithm assumes non-negative edge weights; negative weights can produce incorrect results. Question 23. Kruskal’s algorithm for MST requires edges to be processed in: A) Random order B) Decreasing weight order C) Increasing weight order
D) Order of appearance in adjacency list Answer: C Explanation: Sorting edges by weight ensures the algorithm picks the smallest edges that don’t create cycles. Question 24. The time complexity of the Floyd-Warshall algorithm for a graph with V vertices is: A) O(V) B) O(V log V) C) O(V²) D) O(V³) Answer: D Explanation: It uses three nested loops over all vertices, giving O(V³). Question 25. Linear search has a best-case time complexity of: A) O(1) B) O(log n) C) O(n) D) O(n log n) Answer: A Explanation: If the target is the first element, only one comparison is needed. Question 26. Which sorting algorithm has the best worst-case time complexity? A) Bubble sort B) Insertion sort C) Merge sort D) Selection sort Answer: C Explanation: Merge sort guarantees O(n log n) worst-case performance.
Question 30. Tail-call optimization can transform a recursive function into an equivalent: A) Iterative loop B) Dynamic programming solution C) Divide-and-conquer algorithm D) Parallel algorithm Answer: A Explanation: Tail-call elimination reuses the current stack frame, effectively converting recursion to iteration. Question 31. The Master Theorem applies to recurrences of the form T(n)=a T(n/b)+f(n). For a = 4, b = 2, and f(n)=n², the solution is: A) Θ(n) B) Θ(n log n) C) Θ(n²) D) Θ(n³) Answer: C Explanation: n^{log_b a}=n^{log₂4}=n²; since f(n)=Θ(n²), case 2 gives Θ(n²). Question 32. In dynamic programming, the principle of optimal substructure means: A) Subproblems overlap completely. B) An optimal solution can be constructed from optimal solutions of its subproblems. C) Subproblems are independent. D) The problem can be solved greedily. Answer: B Explanation: Optimal substructure allows building global optimum from local optima. Question 33. Memoization differs from tabulation primarily in that memoization:
A) Uses bottom-up iteration B. Stores results in a table before they are needed C) Computes subproblems on-demand (top-down) D) Requires no extra memory Answer: C Explanation: Memoization caches results as recursive calls occur, whereas tabulation fills a table iteratively. Question 34. Which of the following statements about stack memory is true? A) It grows upward in address space. B) It is automatically deallocated when a function returns. C) It can store dynamically sized objects without explicit allocation. D) It is shared among all threads in a process. Answer: B Explanation: Local variables on the stack are reclaimed when the containing function exits. Question 35. A memory leak most commonly occurs when: A) Stack variables are not initialized. B) Dynamically allocated memory is not freed. C) Pointers are declared as const. D) Arrays are declared with static storage. Answer: B Explanation: Failing to deallocate heap memory leaves it unreachable, causing a leak. Question 36. In C++, the keyword nullptr was introduced to: A) Replace NULL with a type-safe null pointer constant. B) Define a new integer type.
D) O(n log n) Answer: A Explanation: Only the head pointer needs to be updated. Question 40. In a deque, which operation is NOT typically supported in O(1) time? A) Insert at front B) Delete at rear C) Random access by index D) Insert at rear Answer: C Explanation: Deques provide constant-time ends operations but not random indexing. Question 41. Which of the following is a characteristic of a complete binary tree? A) All levels are fully filled except possibly the last, which is filled from left to right. B) Every node has exactly two children. C) The tree is perfectly balanced. D) No leaf node has a sibling. Answer: A Explanation: Completeness requires left-justified filling of the last level. Question 42. The space complexity of the recursive implementation of the Fibonacci sequence (without memoization) is: A) O(1) B) O(log n) C) O(n) D) O(n) stack frames
Answer: D Explanation: Each call creates a new stack frame; depth equals n, giving O(n) space. Question 43. Which hashing technique uses a secondary hash function to compute the probe step size? A) Linear probing B) Quadratic probing C) Double hashing D) Separate chaining Answer: C Explanation: Double hashing combines two hash functions to avoid clustering. Question 44. In a binary heap stored in an array, the parent index of a node at index i (0-based) is: A) i / 2 B) (i-1) / 2 C) 2i + 1 D) 2i + 2 Answer: B Explanation: For 0-based arrays, parent = floor((i-1)/2). Question 45. Which of the following statements about the “Big-Omega” notation is correct? A) It describes an upper bound. B) It describes a lower bound. C) It is equivalent to Big-O. D) It is used only for space analysis. Answer: B Explanation: Ω(f(n)) provides a asymptotic lower bound on a function’s growth.
Question 49. Which of the following is NOT a property of a red-black tree? A) Every node is either red or black. B) The root must be red. C) Red nodes cannot have red children. D) Every path from a node to its leaves has the same number of black nodes. Answer: B Explanation: The root of a red-black tree must be black. Question 50. The time complexity of heap sort on an array of size n is: A) O(n) B) O(n log n) C) O(n²) D) O(log n) Answer: B Explanation: Building the heap takes O(n) and each of n extractions costs O(log n), totaling O(n log n). Question 51. In a priority queue implemented with a binary max-heap, the operation to increase the key of an element requires: A) O(1) B) O(log n) C) O(n) D) O(n log n) Answer: B Explanation: After increasing a key, the element may need to “bubble up” along the height of the heap.
Question 52. Which of the following algorithms is guaranteed to find a minimum-weight spanning tree in a graph that may contain negative edge weights? A) Prim’s algorithm only B) Kruskal’s algorithm only C) Both Prim’s and Kruskal’s D) Neither; negative weights break both algorithms Answer: C Explanation: Both algorithms work with any edge weights, including negatives, as they rely on ordering by weight. Question 53. The average-case time complexity of quick sort is O(n log n). This analysis assumes: A) All pivots are the smallest element. B) Random pivot selection or uniformly distributed inputs. C) The array is already sorted. D) Use of insertion sort for small subarrays. Answer: B Explanation: Random or balanced pivots lead to logarithmic recursion depth on average. Question 54. Which of the following best describes a “singly linked list with a tail pointer”? A) Allows O(1) insertion at both ends. B) Allows O(1) deletion at the tail. C) Allows O(1) insertion at the head and O(1) access to the last node. D) Eliminates need for a head pointer. Answer: C Explanation: The tail pointer gives constant-time access to the last node, while insertion at head remains O(1).
Question 58. Which of the following is a disadvantage of using separate chaining for hash collisions? A) Requires a prime table size. B) Degrades to O(n) search if many elements hash to same bucket. C) Cannot store more elements than the table size. D) Needs complex arithmetic for probing. Answer: B Explanation: If many keys map to one bucket, the linked list in that bucket grows, making searches linear. Question 59. In a breadth-first search, the data structure used to store frontier vertices is a: A) Stack B) Queue C) Priority queue D) Deque Answer: B Explanation: BFS explores vertices level by level, which is naturally modeled by a FIFO queue. Question 60. Which of the following statements about the “divide and conquer” paradigm is FALSE? A) The problem is divided into subproblems of the same type. B) Subproblems are solved independently. C) The solutions are combined to form the final answer. D) It always results in linear time algorithms. Answer: D Explanation: Divide-and-conquer can yield O(n log n), O(n²), etc.; it does not guarantee linear time.
Question 61. The amortized time complexity of inserting n elements into a dynamic array (vector) that doubles its capacity when full is: A) O(1) per insertion B) O(log n) per insertion C) O(n) per insertion D) O(n log n) total Answer: A Explanation: Although occasional resizing costs O(n), the average cost per insertion stays constant. Question 62. Which of the following best describes a “sparse matrix” storage technique? A) Store all elements in a 2-D array. B) Store only non-zero elements with their coordinates. C) Use a linked list for each row. D) Convert to a dense matrix before processing. Answer: B Explanation: Sparse representations keep only meaningful (non-zero) entries to save space. Question 63. In a circular doubly linked list, the next pointer of the last node points to: A) NULL B) The first node C) Itself D) The second node Answer: B Explanation: Circularity connects the tail back to the head, maintaining bidirectional links.