Deck 12: Recursion
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/35
Play
Full screen (f)
Deck 12: Recursion
1
Each time a function is called in a recursive solution,the system incurs overhead that is not incurred with a loop.
True
2
In a recursive solution,if the problem cannot be solved now,then a recursive function reduces it to a smaller but similar problem and
A) exits
B) returns to the main function
C) returns to the calling function
D) calls itself to solve the smaller problem
A) exits
B) returns to the main function
C) returns to the calling function
D) calls itself to solve the smaller problem
D
3
The process of calling a function requires
A) a slow memory access
B) a quick memory access
C) several actions to be performed by the computer
D) one action to be performed by the computer
A) a slow memory access
B) a quick memory access
C) several actions to be performed by the computer
D) one action to be performed by the computer
C
4
What is the first step to take in order to apply a recursive approach?
A) Identify at least one case in which the problem can be solved without recursion.
B) Determine a way to solve the problem in all circumstances using recursion.
C) Identify a way to stop the recursion.
D) Determine a way to return to the main function.
A) Identify at least one case in which the problem can be solved without recursion.
B) Determine a way to solve the problem in all circumstances using recursion.
C) Identify a way to stop the recursion.
D) Determine a way to return to the main function.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
5
What is the second step to take in order to apply a recursive approach?
A) Identify at least one case in which the problem can be solved without recursion.
B) Determine a way to use recursion to solve the problem in all circumstances which cannot be solved without recursion.
C) Determine a way to return to the main function.
D) Identify a way to stop the recursion.
A) Identify at least one case in which the problem can be solved without recursion.
B) Determine a way to use recursion to solve the problem in all circumstances which cannot be solved without recursion.
C) Determine a way to return to the main function.
D) Identify a way to stop the recursion.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
6
If a recursive solution is evident for a particular problem,and if the recursive algorithm does not slow system performance by an intolerable amount,then recursion would probably be a good design choice.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
7
If,in a recursive solution,function A calls function B which calls function C,this is called __________ recursion.
A) continuous
B) direct
C) three function call
D) indirect
A) continuous
B) direct
C) three function call
D) indirect
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
8
There must be only one function involved in any recursive solution.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
9
If a problem can be solved immediately without recursion,then the recursive function
A) solves it and returns
B) exits
C) returns a default value
D) generates a run-time error
A) solves it and returns
B) exits
C) returns a default value
D) generates a run-time error
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
10
The base case is the case in which the problem can be solved without
A) loops
B) decisions
C) objects
D) recursion
A) loops
B) decisions
C) objects
D) recursion
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
11
A recursive function must have some way to control the number of times it repeats.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
12
When,in a recursive solution,function A calls function B which,in turn,calls function A,this is known as indirect recursion.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
13
Recursion is sometimes required to solve certain types of problems.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
14
Which of the following describes the base case in a recursive solution?
A) a case in which the problem can be solved without recursion
B) the case in which the problem is solved through recursion
C) the way to stop the recursion
D) the way to return to the main function
A) a case in which the problem can be solved without recursion
B) the case in which the problem is solved through recursion
C) the way to stop the recursion
D) the way to return to the main function
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
15
A problem can normally be solved with recursion if it can be broken down into smaller problems that are identical in structure to the overall problem.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
16
Recursion is
A) never required to solve a problem
B) required to solve certain mathematical problems
C) sometimes required to solve string problems
D) required to solve some problems
A) never required to solve a problem
B) required to solve certain mathematical problems
C) sometimes required to solve string problems
D) required to solve some problems
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
17
A base case is not necessary for all recursive algorithms.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
18
Recursive algorithms are always more concise and efficient than iterative algorithms.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
19
A problem can be solved with recursion if it can be broken down into __________ problems.
A) smaller
B) one-line
C) manageable
D) modular
A) smaller
B) one-line
C) manageable
D) modular
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
20
In many cases it is easier to see how to solve a problem with recursion than with a loop.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
21
A recursion in which a function directly calls itself is known as ___________ recursion.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
22
Recursive function calls are __________ efficient than loops.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
23
A function is called from the main function and then it calls itself five times.
The depth of recursion is __________.
The depth of recursion is __________.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
24
The majority of repetitive programming tasks are best done with ___________.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
25
A function is called from the main function for the first time and then calls itself seven times. What is the depth of recursion?
A) 8
B) 2
C) 1
D) 7
A) 8
B) 2
C) 1
D) 7
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
26
A recursive function includes __________ which are not necessary in a loop structure.
A) function calls
B) conditional clauses
C) overhead actions
D) object instances
A) function calls
B) conditional clauses
C) overhead actions
D) object instances
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
27
Recursive functions are __________ iterative algorithms.
A) more efficient than
B) less efficient than
C) as efficient as
D) impossible to compare to
A) more efficient than
B) less efficient than
C) as efficient as
D) impossible to compare to
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
28
Some problems are more __________ solved with recursion than with a loop.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
29
What defines the depth of recursion?
A) the length of the algorithm
B) the number of function calls
C) the number of times the function calls itself
D) the number of times the function goes to the base case
A) the length of the algorithm
B) the number of function calls
C) the number of times the function calls itself
D) the number of times the function goes to the base case
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
30
All the cases of a recursive solution other than the base case are called the __________ case.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
31
A solution using a(n)__________ is usually more evident than a recursive solution.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
32
Usually a problem solved by recursion is reduced by making the value of one or more parameters __________ with each recursive call.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
33
Which would be the base case in a recursive solution to the problem of finding the factorial of a number. Recall that the factorial of a non-negative whole number is defined as n! where:
If n = 0,then n! = 1
If n > 0,then n! = 1 x 2 x 3 x ...
X n
A) n = 0
B) n = 1
C) n > 0
D) The factorial of a number cannot be solved with recursion.
If n = 0,then n! = 1
If n > 0,then n! = 1 x 2 x 3 x ...
X n
A) n = 0
B) n = 1
C) n > 0
D) The factorial of a number cannot be solved with recursion.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
34
The base case does not require __________,so it stops the chain of recursive calls.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck
35
Each time a function is called,the system incurs __________ that is not necessary with a loop.
Unlock Deck
Unlock for access to all 35 flashcards in this deck.
Unlock Deck
k this deck