Deck 15: Recursion

Full screen (f)
exit full mode
Question
Look at the following pseudocode algorithm. algorithm Test14(int x)
If (x < 8)
Return (2 * x)
Else
Return (3 * Test14(x - 8)+ 8)
End Test14
What value is returned for Test14(7)?

A) 0
B) 7
C) 14
D) -5
Use Space or
up arrow
down arrow
to flip the card.
Question
Look at the following pseudocode algorithm. Algorithm Test3(int a,int b)
If (a < b)
Return 5
Else if ( a == b)
Return -5;
Else
Return (a + Test3(a - 1,b)
End Test3
What is the base case for the algorithm?

A) a < b
B) a == b
C) Both a and b
D) Neither a or b
Question
Look at the following method. public static int test2(int x,int y)
{
If ( x < y)
{
Return -5;
}
Else
{
Return (test2(x - y,y + 5)+ 6);
}
}
What is the recursive case for the method?

A) x < y
B) -5
C) x >= y
D) x != y
Question
The depth of recursion is

A) the number of times that a method calls itself.
B) the value returned from the last recursive call.
C) the value that will terminate the recursive calls.
D) There is no such term.
Question
Look at the following pseudocode algorithm. algorithm Test14(int x)
If (x < 8)
Return (2 * x)
Else
Return (3 * Test14(x - 8)+ 8)
End Test14
What is the recursive case for the algorithm?

A) x < 8
B) 2 * x
C) x != 8
D) x >= 8
Question
Look at the following pseudocode algorithm. algorithm Test14(int x)
If (x < 8)
Return (2 * x)
Else
Return (3 * Test14(x - 8)+ 8)
End Test14
What is the base case for the algorithm?

A) x < 8
B) 2 * x
C) 3 * Test14(x - 8)+ 8
D) x >= 8
Question
How many times will the following method call itself,if 10 is passed as the argument? public static void message(int n)
{
If (n > 0)
{
System.out.println("Print this line. \ n");
Message(n + 1);
}
}

A) 1
B) 9
C) 10
D) An infinite number of times
Question
Like a loop,a recursive method must have

A) a counter.
B) some way to control the number of times it repeats itself.
C) a return statement.
D) a predetermined number of times it will execute before terminating.
Question
A recursive method is a method that

A) uses four-letter words to tell you when you have an error.
B) keeps recurring in your program code.
C) calls itself.
D) is a method that has a loop in it.
Question
Look at the following method. public static int test2(int x,int y)
{
If ( x < y)
{
Return -5;
}
Else
{
Return (test2(x - y,y + 5)+ 6);
}
}
What is returned for test2(18,5)?

A) 6
B) -5
C) 7
D) 1
Question
The actions that the JVM must perform any time a method is called is called

A) stack frame.
B) overhead.
C) housekeeping.
D) method calls.
Question
Look at the following method. public static int test2(int x,int y)
{
If ( x < y)
{
Return -5;
}
Else
{
Return (test2(x - y,y + 5)+ 6);
}
}
What is the depth of test2(18,5)?

A) 0
B) 1
C) 2
D) 3
Question
The Towers of Hanoi is

A) a mathematical game
B) often used in computer science textbooks
C) demonstrates the power of recursion
D) All of the above
Question
Look at the following method. public static int test2(int x,int y)
{
If ( x < y)
{
Return -5;
}
Else
{
Return (test2(x - y,y + 5)+ 6);
}
}
What is returned for test2(10,20)?

A) 6
B) 10
C) 1
D) -5
Question
Look at the following pseudocode algorithm. Algorithm Test3(int a,int b)
If (a < b)
Return 5
Else if ( a == b)
Return -5;
Else
Return (a + Test3(a - 1,b)
End Test3
What is the recursive case for the algorithm?

A) a < b
B) a == b
C) a > b
D) None of the above
Question
Look at the following pseudocode algorithm. algorithm Test14(int x)
If (x < 8)
Return (2 * x)
Else
Return (3 * Test14(x - 8)+ 8)
End Test14
What value is returned for Test14(16)?

A) 8
B) 16
C) 24
D) 32
Question
Look at the following pseudocode algorithm. algorithm Test14(int x)
If (x < 8)
Return (2 * x)
Else
Return (3 * Test14(x - 8)+ 8)
End Test14
What is the depth of Test14(7)?

A) 0
B) 1
C) 6
D) 7
Question
Look at the following pseudocode algorithm. algorithm Test14(int x)
If (x < 8)
Return (2 * x)
Else
Return (3 * Test14(x - 8)+ 8)
End Test14
What is the depth of Test14(16)?

A) 0
B) 1
C) 2
D) 3
Question
To solve a program recursively,you need to identify at least one case in which the problem can be solved without recursion - this is known as

A) the recursive case.
B) the terminal case.
C) the base case.
D) the final case.
Question
Look at the following method. public static int Test2(int x,int y)
{
If ( x < y)
{
Return -5;
}
Else
{
Return (Test2(x - y,y + 5)+ 6);
}
}
What is the base case for the method?

A) x < y
B) -5
C) Test2(x - y,y + 5)+ 6
D) +6
Question
This type of method is a method that calls itself.

A) Looping
B) Circular
C) Recursive
D) Reoccurring
Question
Recursive algorithms are usually less efficient than iterative algorithms.
Question
Like _________,a recursive method must have some way to control the number of times it repeats.

A) a loop
B) any method
C) a GUI method
D) a rumor
Question
A problem can be solved recursively if it can be broken down into successive smaller problems that are unique within the overall problem.
Question
The part of a problem that is solved with recursion is known as the

A) terminal case
B) final case
C) re-occurring case
D) recursive case
Question
Which of the following problems cannot be programmed recursively?

A) Towers of Hanoi
B) Summing a range of array elements
C) Finding the greatest common divisor
D) All of the above can be programmed recursively
Question
If Method A calls Method B which in turn calls Method A,it is called indirect recursion.
Question
How many times will the following method call itself,if 10 is passed as the argument? public static void message(int n)
{
If (n < 0)
{
System.out.println("Print this line. \ n");
Message(n + 1);
}
}

A) 0
B) 9
C) 10
D) An infinite number of times
Question
Look at the following pseudocode algorithm. Algorithm gcd(x,y)
If (x < y)
Gcd (y,x)
Else
If (y = 0)
Return x
Else
Return gcd(y,x mod y)
End gcd
What is the base case for the algorithm gcd?

A) x < y
B) y == 0
C) x == 0
D) y > x
Question
Any problem that can be solved recursively can also be solved iteratively.
Question
Look at the following pseudocode algorithm. Algorithm gcd(x,y)
If (x < y)
Gcd (y,x)
Else
If (y = 0)
Return x
Else
Return gcd(y,x mod y)
End gcd
What is returned from gcd(60,24)?

A) 60
B) 24
C) 12
D) 66
Question
The number of times that a method calls itself is known as the

A) height of recursion
B) depth of recursion
C) width of recursion
D) length of recursion
Question
Indirect recursion occurs when a method calls another method that in turn calls the first method.
Question
A problem can be solved recursively if it can be broken down into successive smaller problems that are identical to the overall problem.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/34
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 15: Recursion
1
Look at the following pseudocode algorithm. algorithm Test14(int x)
If (x < 8)
Return (2 * x)
Else
Return (3 * Test14(x - 8)+ 8)
End Test14
What value is returned for Test14(7)?

A) 0
B) 7
C) 14
D) -5
C
2
Look at the following pseudocode algorithm. Algorithm Test3(int a,int b)
If (a < b)
Return 5
Else if ( a == b)
Return -5;
Else
Return (a + Test3(a - 1,b)
End Test3
What is the base case for the algorithm?

A) a < b
B) a == b
C) Both a and b
D) Neither a or b
C
3
Look at the following method. public static int test2(int x,int y)
{
If ( x < y)
{
Return -5;
}
Else
{
Return (test2(x - y,y + 5)+ 6);
}
}
What is the recursive case for the method?

A) x < y
B) -5
C) x >= y
D) x != y
C
4
The depth of recursion is

A) the number of times that a method calls itself.
B) the value returned from the last recursive call.
C) the value that will terminate the recursive calls.
D) There is no such term.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
5
Look at the following pseudocode algorithm. algorithm Test14(int x)
If (x < 8)
Return (2 * x)
Else
Return (3 * Test14(x - 8)+ 8)
End Test14
What is the recursive case for the algorithm?

A) x < 8
B) 2 * x
C) x != 8
D) x >= 8
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
6
Look at the following pseudocode algorithm. algorithm Test14(int x)
If (x < 8)
Return (2 * x)
Else
Return (3 * Test14(x - 8)+ 8)
End Test14
What is the base case for the algorithm?

A) x < 8
B) 2 * x
C) 3 * Test14(x - 8)+ 8
D) x >= 8
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
7
How many times will the following method call itself,if 10 is passed as the argument? public static void message(int n)
{
If (n > 0)
{
System.out.println("Print this line. \ n");
Message(n + 1);
}
}

A) 1
B) 9
C) 10
D) An infinite number of times
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
8
Like a loop,a recursive method must have

A) a counter.
B) some way to control the number of times it repeats itself.
C) a return statement.
D) a predetermined number of times it will execute before terminating.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
9
A recursive method is a method that

A) uses four-letter words to tell you when you have an error.
B) keeps recurring in your program code.
C) calls itself.
D) is a method that has a loop in it.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
10
Look at the following method. public static int test2(int x,int y)
{
If ( x < y)
{
Return -5;
}
Else
{
Return (test2(x - y,y + 5)+ 6);
}
}
What is returned for test2(18,5)?

A) 6
B) -5
C) 7
D) 1
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
11
The actions that the JVM must perform any time a method is called is called

A) stack frame.
B) overhead.
C) housekeeping.
D) method calls.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
12
Look at the following method. public static int test2(int x,int y)
{
If ( x < y)
{
Return -5;
}
Else
{
Return (test2(x - y,y + 5)+ 6);
}
}
What is the depth of test2(18,5)?

A) 0
B) 1
C) 2
D) 3
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
13
The Towers of Hanoi is

A) a mathematical game
B) often used in computer science textbooks
C) demonstrates the power of recursion
D) All of the above
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
14
Look at the following method. public static int test2(int x,int y)
{
If ( x < y)
{
Return -5;
}
Else
{
Return (test2(x - y,y + 5)+ 6);
}
}
What is returned for test2(10,20)?

A) 6
B) 10
C) 1
D) -5
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
15
Look at the following pseudocode algorithm. Algorithm Test3(int a,int b)
If (a < b)
Return 5
Else if ( a == b)
Return -5;
Else
Return (a + Test3(a - 1,b)
End Test3
What is the recursive case for the algorithm?

A) a < b
B) a == b
C) a > b
D) None of the above
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
16
Look at the following pseudocode algorithm. algorithm Test14(int x)
If (x < 8)
Return (2 * x)
Else
Return (3 * Test14(x - 8)+ 8)
End Test14
What value is returned for Test14(16)?

A) 8
B) 16
C) 24
D) 32
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
17
Look at the following pseudocode algorithm. algorithm Test14(int x)
If (x < 8)
Return (2 * x)
Else
Return (3 * Test14(x - 8)+ 8)
End Test14
What is the depth of Test14(7)?

A) 0
B) 1
C) 6
D) 7
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
18
Look at the following pseudocode algorithm. algorithm Test14(int x)
If (x < 8)
Return (2 * x)
Else
Return (3 * Test14(x - 8)+ 8)
End Test14
What is the depth of Test14(16)?

A) 0
B) 1
C) 2
D) 3
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
19
To solve a program recursively,you need to identify at least one case in which the problem can be solved without recursion - this is known as

A) the recursive case.
B) the terminal case.
C) the base case.
D) the final case.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
20
Look at the following method. public static int Test2(int x,int y)
{
If ( x < y)
{
Return -5;
}
Else
{
Return (Test2(x - y,y + 5)+ 6);
}
}
What is the base case for the method?

A) x < y
B) -5
C) Test2(x - y,y + 5)+ 6
D) +6
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
21
This type of method is a method that calls itself.

A) Looping
B) Circular
C) Recursive
D) Reoccurring
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
22
Recursive algorithms are usually less efficient than iterative algorithms.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
23
Like _________,a recursive method must have some way to control the number of times it repeats.

A) a loop
B) any method
C) a GUI method
D) a rumor
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
24
A problem can be solved recursively if it can be broken down into successive smaller problems that are unique within the overall problem.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
25
The part of a problem that is solved with recursion is known as the

A) terminal case
B) final case
C) re-occurring case
D) recursive case
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
26
Which of the following problems cannot be programmed recursively?

A) Towers of Hanoi
B) Summing a range of array elements
C) Finding the greatest common divisor
D) All of the above can be programmed recursively
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
27
If Method A calls Method B which in turn calls Method A,it is called indirect recursion.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
28
How many times will the following method call itself,if 10 is passed as the argument? public static void message(int n)
{
If (n < 0)
{
System.out.println("Print this line. \ n");
Message(n + 1);
}
}

A) 0
B) 9
C) 10
D) An infinite number of times
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
29
Look at the following pseudocode algorithm. Algorithm gcd(x,y)
If (x < y)
Gcd (y,x)
Else
If (y = 0)
Return x
Else
Return gcd(y,x mod y)
End gcd
What is the base case for the algorithm gcd?

A) x < y
B) y == 0
C) x == 0
D) y > x
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
30
Any problem that can be solved recursively can also be solved iteratively.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
31
Look at the following pseudocode algorithm. Algorithm gcd(x,y)
If (x < y)
Gcd (y,x)
Else
If (y = 0)
Return x
Else
Return gcd(y,x mod y)
End gcd
What is returned from gcd(60,24)?

A) 60
B) 24
C) 12
D) 66
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
32
The number of times that a method calls itself is known as the

A) height of recursion
B) depth of recursion
C) width of recursion
D) length of recursion
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
33
Indirect recursion occurs when a method calls another method that in turn calls the first method.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
34
A problem can be solved recursively if it can be broken down into successive smaller problems that are identical to the overall problem.
Unlock Deck
Unlock for access to all 34 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 34 flashcards in this deck.