/MODULE TWO : REVIEW QUESTIONS EIGHTEEN TO TWENTY
/MODULE TWO : REVIEW QUESTIONS EIGHTEEN TO TWENTY
One. What is recursion in the context of algorithms?
Choices:
. A method that exclusively uses loops to solve problems
· A technique that avoids using functions entirely
. A process where a function calls itself directly or indirectly
. A process where a function calls another function repeatedly Explanation: A function solves a problem by calling itself
Two. Which of the following best describes the difference between iteration and recursion?
Choices:
. Recursion is always faster than iteration
. Iteration uses the stack while recursion does not
· Iteration uses repetition structures while recursion uses selection structures
. Recursion consumes less memory than iteration Explanation: Loops vs. recursive function with conditions.
Three. What is the primary reason for defining a base case in a recursive function?
Choices:
. To avoid infinite loops
. To allow multiple functions to be called simultaneously
· To reduce memory usage
. To increase execution speed Explanation: Base case stops the recursion.
Four. In the context of recursion, what is tail recursion?
Choices:
. When the function calls another function instead of itself
. When the recursive call happens at the beginning of the function
. When there are multiple recursive calls within the same function
. When the recursive call is the last operation performed in the function Explanation: Nothing is left to do after the call; can be optimized.
Five. What is the output of the following recursive function when
N equals three? int fun(int n) { if (n equals one) return one; else return one plus fun(n minus one) } Choices:
Explanation: fun of three equals one plus fun of two equals three. Six. What is the time complexity of an algorithm that checks each triple in an array of size N?
Choices:
·
O of N · O of N cubed
·
O of log N ·
O of N log N Explanation: Three nested loops -> cubic growth.
Seven. Which asymptotic notation represents the worst-case scenario of an algorithm's running time?
Seven. Which asymptotic notation represents the worst-case scenario of an algorithm's running time?
Choices:
· Q (Omega)
· Beta
· O (Theta)
· O (Big Oh) Explanation: Big O shows maximum running time.