IS 122
Programming Logic
Midterms Exam Review (Qns & Ans)
2025
1. Which of the following data structures is most efficient for
implementing a recursive depth-first search algorithm?
A. Queue
B. Stack
C. Hash Table
D. Array
- ANS: B. Stack
- Rationale: Depth-first search relies on the Last-In-First-Out
(LIFO) principle, making a stack the most suitable data structure.
©2025
,2. What is the primary benefit of using modular programming in
software design?
A. Reduces program execution time
B. Simplifies debugging and code maintenance
C. Increases code redundancy
D. Avoids the use of libraries
- ANS: B. Simplifies debugging and code maintenance
- Rationale: Modular programming divides code into reusable
and manageable parts, facilitating debugging and updates.
3. In a binary search algorithm, what condition must the input
array meet for the algorithm to function correctly?
A. The array must be unsorted.
B. The array must contain no duplicate elements.
C. The array must be sorted.
D. The array must have a fixed size.
- ANS: C. The array must be sorted.
- Rationale: Binary search works by dividing the array into
halves, a process that only works with sorted data.
4. Which programming construct is used to ensure mutual
exclusion in multithreaded programming?
©2025
, A. Loop
B. Semaphore
C. Array
D. Function
- ANS: B. Semaphore
- Rationale: Semaphores regulate access to shared resources
to prevent race conditions in multithreading.
5. What is the time complexity of the merge sort algorithm in the
worst case?
A. \( O(n^2) \)
B. \( O(n \log n) \)
C. \( O(n) \)
D. \( O(\log n) \)
- ANS: B. \( O(n \log n) \)
- Rationale: Merge sort divides the data into smaller subsets
and sorts them, achieving a logarithmic divide-and-conquer
efficiency.
---
Fill-in-the-Blank Questions
©2025
Programming Logic
Midterms Exam Review (Qns & Ans)
2025
1. Which of the following data structures is most efficient for
implementing a recursive depth-first search algorithm?
A. Queue
B. Stack
C. Hash Table
D. Array
- ANS: B. Stack
- Rationale: Depth-first search relies on the Last-In-First-Out
(LIFO) principle, making a stack the most suitable data structure.
©2025
,2. What is the primary benefit of using modular programming in
software design?
A. Reduces program execution time
B. Simplifies debugging and code maintenance
C. Increases code redundancy
D. Avoids the use of libraries
- ANS: B. Simplifies debugging and code maintenance
- Rationale: Modular programming divides code into reusable
and manageable parts, facilitating debugging and updates.
3. In a binary search algorithm, what condition must the input
array meet for the algorithm to function correctly?
A. The array must be unsorted.
B. The array must contain no duplicate elements.
C. The array must be sorted.
D. The array must have a fixed size.
- ANS: C. The array must be sorted.
- Rationale: Binary search works by dividing the array into
halves, a process that only works with sorted data.
4. Which programming construct is used to ensure mutual
exclusion in multithreaded programming?
©2025
, A. Loop
B. Semaphore
C. Array
D. Function
- ANS: B. Semaphore
- Rationale: Semaphores regulate access to shared resources
to prevent race conditions in multithreading.
5. What is the time complexity of the merge sort algorithm in the
worst case?
A. \( O(n^2) \)
B. \( O(n \log n) \)
C. \( O(n) \)
D. \( O(\log n) \)
- ANS: B. \( O(n \log n) \)
- Rationale: Merge sort divides the data into smaller subsets
and sorts them, achieving a logarithmic divide-and-conquer
efficiency.
---
Fill-in-the-Blank Questions
©2025