Module 2 Flashcards
Memorization
It is a process in which a function calls itself directly or
indirectly.
Recursion
It is a process which breaks a task into smaller subtasks.
Recursion
(smaller subtask)
It is a powerful technique that can be used in place of
iterations.
Recursion
(powerful technique)
True or False. A base case should be defined to avoid infinite loops.
True
The ________ is when a loop repeatedly executes until the controlling condition becomes false.
Iteration
(loop repeatedly executes)
True or False. Recursion and Iteration both repeatedly execute the set of instructions.
True
True or False. Recursion is applied to the set of instructions which we want to get repeatedly executed.
False
(ITERATION is applied to the set of instructions which we want to get repeatedly executed)
True or False. Recursion is a process, always applied to a function.
True
Iteration uses _______ structure.
Repetition
True or False. An infinite loop occurs with iteration if the loop condition test never becomes true and Infinite looping uses CPU cycles repeatedly.
False
(An infinite loop occurs with iteration if the loop condition test never becomes FALSE)
True or False. An iteration does not use the stack so it’s faster than recursion.
True
True or False. An iteration terminates when the loop condition is satisfied.
False
( An iteration terminates when the loop condition FAILS)
Recursion uses ______ structure.
Selection
True or False. Iteration consumes less memory but makes the code longer.
True
True or False. Recursion terminates when a base case is recognized.
True
True or False. Infinite recursion occurs if the recursion step does not reduce the problem in a manner that converges on some condition (base case) and Infinite recursion can crash the system.
True
True or False. Recursion is usually faster than iteration despite the overhead of maintaining the stack.
False
(Recursion is usually SLOWER than iteration DUE TO the overhead of maintaining the stack)
True or False. Recursion uses less memory than iteration.
False
(Recursion uses MORE memory than iteration)
True or False. Recursion makes the code smaller.
True
What are the 4 types of recursion?
(DINT)
- Direct Recursion
- Indirect Recursion
- Tail Recursion
- Non-Tail Recursion
This type of recursion calls the same function again.
Direct Recursion
This type of recursion calls another function which then calls the same function again.
Indirect Recursion
This type of recursion has a recursive call as the last thing done by the function.
Tail Recursion
(recursive call is the last thing done)
This type of recursion’s recursive call is not the last thing done by the recursion.
Non-Tail Recursion
(recursive call is not the las thing done)