Deck 11: 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
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/44
Play
Full screen (f)
Deck 11: Recursion
1
All recursive methods have a/an ____________ equivalent method.
A)Iterative
B)Selective
C)Inherited
D)None of the above
A)Iterative
B)Selective
C)Inherited
D)None of the above
A
2
A method definition that includes a call to itself is said to be recursive.
True
3
The portion of memory in which a recursive computation is stored is called a/an:
A)stack frame
B)activation record
C)all of the above
D)none of the above
A)stack frame
B)activation record
C)all of the above
D)none of the above
C
4
A recursive solution can be preferable to an iterative solution because:
A)recursive method calls are faster than iterative looping
B)recursive solutions may be easier to understand than iterative ones
C)recursion uses less memory than iteration
D)iteration should be avoided.
A)recursive method calls are faster than iterative looping
B)recursive solutions may be easier to understand than iterative ones
C)recursion uses less memory than iteration
D)iteration should be avoided.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
5
Pick the best answer
A)Recursive methods may include a recursive call
B)Recursive methods may not use iteration
C)Recursive methods must include a recursive call
D)none of the above
A)Recursive methods may include a recursive call
B)Recursive methods may not use iteration
C)Recursive methods must include a recursive call
D)none of the above
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
6
Recursion is:
A)the ability of a program to repeat a block of code
B)the ability of a method to call itself
C)the ability of a method to call smaller methods
D)the ability of a method to implement factorials
A)the ability of a program to repeat a block of code
B)the ability of a method to call itself
C)the ability of a method to call smaller methods
D)the ability of a method to implement factorials
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
7
The stack is a ________________ data structure.
A)first in - first out
B)last in - last out
C)last in - first out
D)none of the above
A)first in - first out
B)last in - last out
C)last in - first out
D)none of the above
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
8
A recursive method is one that:
A)Returns a value
B)Initializes a set of variables
C)Returns no value
D)Invokes itself
A)Returns a value
B)Initializes a set of variables
C)Returns no value
D)Invokes itself
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
9
During recursion,if the stack attempts to grow beyond its limit,a _____________ occurs.
A)Stack underflow
B)Stack overflow
C)Recursive underflow
D)Recursive overflow
A)Stack underflow
B)Stack overflow
C)Recursive underflow
D)Recursive overflow
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
10
What is the value returned when the integer 5 is the argument to the factorial method?
A)15
B)50
C)100
D)120
A)15
B)50
C)100
D)120
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
11
When defining recursive void methods you should:
A)Ensure there is no infinite recursion.
B)Ensure that each stopping case performs the correct action for that case.
C)Ensure that if all recursive calls perform their actions correctly,then the entire case performs correctly.
D)All of the above
A)Ensure there is no infinite recursion.
B)Ensure that each stopping case performs the correct action for that case.
C)Ensure that if all recursive calls perform their actions correctly,then the entire case performs correctly.
D)All of the above
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
12
A base case must include a recursive call.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
13
The following code for the method factorial)applies to the next two questions: public static double factorial double n)
{
If n == 0)
{
Return 1;
}
Else
{
Return n * factorialn-1);
}
}
What is the value returned when the integer 3 is the argument to the factorial method?
A)2
B)4
C)6
D)8
{
If n == 0)
{
Return 1;
}
Else
{
Return n * factorialn-1);
}
}
What is the value returned when the integer 3 is the argument to the factorial method?
A)2
B)4
C)6
D)8
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
14
The underlying data structure used by the computer during recursion is a:
A)queue
B)linked list
C)tree
D)stack
A)queue
B)linked list
C)tree
D)stack
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
15
When a recursive call is encountered,computation is temporarily suspended;all of the information needed to continue the computation is saved and the recursive call is evaluated.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
16
Infinite recursion:
A)will happen when there is no base case
B)will not happen when there is a base case
C)will not happen if we use subproblems
D)none of the above
A)will happen when there is no base case
B)will not happen when there is a base case
C)will not happen if we use subproblems
D)none of the above
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
17
When defining recursive valued methods you should:
A)Ensure there is no infinite recursion.
B)Ensure each stopping case returns the correct value for that case.
C)Ensure that the final value returned by the method is the correct value.
D)All of the above
A)Ensure there is no infinite recursion.
B)Ensure each stopping case returns the correct value for that case.
C)Ensure that the final value returned by the method is the correct value.
D)All of the above
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
18
The order of magnitude of the binary search algorithm is:
A)linear
B)exponential
C)logarithmic
D)quadratic
A)linear
B)exponential
C)logarithmic
D)quadratic
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
19
Regarding recursion,if a base case is never reached the result is:
A)infinite recursion
B)iteration
C)termination
D)all of the above
A)infinite recursion
B)iteration
C)termination
D)all of the above
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
20
All recursive methods must have a/an:
A)starting case
B)intermediate case
C)stopping case
D)none of the above
A)starting case
B)intermediate case
C)stopping case
D)none of the above
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
21
The binary search algorithm is extremely slow compared to an algorithm that simply tries all array elements in order.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
22
What is a base case?
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
23
Write a recursive method to compute the power of x< sup >n< /sup > for non-negative n.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
24
Write a recursive method to compute the factorial of a number.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
25
Activation records are used to implement recursion.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
26
The binary search algorithm has worst-case running time that is logarithmic.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
27
How does the computer system handle a recursive method call?
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
28
Write an iterative method to compute the power of x< sup >n< /sup > for non-negative n.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
29
Explain the concept of divide and conquer.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
30
A recursive method must never return a value.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
31
Binary search is a divide and conquer algorithm.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
32
Explain how a sequential search works.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
33
Write a recursive method to print a string backwards.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
34
Explain how the binary search works.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
35
Write an iterative method to print a string backwards.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
36
A recursively written method will usually run slower and use more storage than an equivalent iterative version.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
37
A stack is a last-in/first-out memory structure.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
38
To keep track of recursion most computer systems us a structure called a queue.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
39
What are the criteria you must consider when formulating a recursive solution?
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
40
Write an iterative method to compute the factorial of a number.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
41
What is an activation record?
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
42
What are two factors that contribute to the inefficiency of some recursive solutions?
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
43
What are the two base cases for a recursive binary search algorithm?
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
44
What is a stack overflow?
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck