Fundamentals of Programming
3.0 Credits
Midterm Exam Review (Qns & Ans)
2025
©2025
, Multiple Choice Questions (10 Questions)
1. Question:
Which of the following statements about tail recursion is true?
a. Tail recursion always leads to increased time complexity.
b. Tail recursion enables tail-call optimization, thereby reducing
the call stack usage.
c. Tail recursion requires storing additional state between
recursive calls.
d. Tail recursion results in non-terminating loops.
ANS:
b. Tail recursion enables tail-call optimization, thereby reducing
the call stack usage.
Rationale:
When a recursive call is the last operation in a function, the
compiler or interpreter can optimize it by reusing the current
function’s stack frame. This reduces memory overhead and
prevents stack overflow for deep recursive calls.
2. Question:
Big-O notation is used to describe the efficiency of an algorithm.
Which algorithm typically has a worst-case time complexity of O(n
log n)?
a. Linear search
b. Merge sort
c. Binary search
d. Bubble sort
ANS:
b. Merge sort
Rationale:
Merge sort divides the input into halves, recursively sorts them,
and then merges the sorted halves. Its divide-and-conquer
approach yields a worst-case running time of O(n log n).
©2025
, 3. Question:
Which technique is most effective for optimizing recursive
functions by avoiding redundant computations?
a. Loop unrolling
b. Divide and conquer
c. Memoization
d. Branch prediction
ANS:
c. Memoization
Rationale:
Memoization caches the results of function calls so that repeated
invocations with the same parameters can return the cached result,
significantly decreasing redundant computations in recursive
algorithms.
4. Question:
In C programming, dynamic memory allocation is performed
using which of the following pair of functions?
a. malloc() and free()
b. new and delete
c. alloc() and dealloc()
d. calloc() and realloc() exclusively
ANS:
a. malloc() and free()
Rationale:
In C, the standard functions malloc() for allocating memory and
free() for deallocating it are used for dynamic memory
management. (Note that new and delete are used in C++.)
5. Question:
In parameter passing, which description best fits "pass by
reference"?
a. Passing a copy of the variable’s value.
©2025