Deck 16: Recursion

ملء الشاشة (f)
exit full mode
سؤال
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 the:

A) recursive case
B) terminal case
C) base case
D) final case
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
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
سؤال
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
سؤال
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
سؤال
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
سؤال
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
سؤال
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
سؤال
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
سؤال
Recursion can be a powerful tool for solving:

A) basic problems
B) repetitive problems
C) object-oriented problems
D) binary problems
سؤال
Usually, a problem is reduced by making the value of one or more parameters ________ with each recursive call.

A) larger
B) smaller
C) negative
D) equal
سؤال
Recursive algorithms are usually less efficient than:

A) iterative algorithms
B) quantum algorithms
C) pseudocode algorithms
D) none of the above
سؤال
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
سؤال
How many times will the following method call itself if the value 10 is passed as an 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
سؤال
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
سؤال
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
سؤال
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) The order in which the method appears on the stack
سؤال
A recursive method is:

A) a method that accepts no arguments
B) a method that contains a static field
C) a method that calls itself
D) a method that has a loop
سؤال
The actions that the JVM must perform any time a method is called are known as:

A) Stack depth
B) Overhead
C) Housekeeping
D) Method calls
سؤال
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
سؤال
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
سؤال
Indirect recursion occurs when:

A) a loop is used to solve a recursive problem
B) a recursive method has no code to stop it from repeating
C) a method calls itself
D) a method calls itself from another method
سؤال
A problem can be solved recursively if it can be broken down into successive smaller problems that are unique within the overall problem.
سؤال
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
سؤال
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 nor B
سؤال
If the base case in a recursive method is never reached:

A) the method will call itself only once
B) the result will always be off by one
C) the method will call itself indefinitely
D) the method will never call itself
سؤال
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
سؤال
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
سؤال
Any problem that can be solved recursively can also be solved iteratively.
سؤال
How many times will the following method call itself if the value 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
سؤال
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
سؤال
This type of method is a method that calls itself.

A) Looping
B) Circular
C) Recursive
D) Reoccurring
سؤال
Indirect recursion occurs when a method calls another method that in turn calls the first method.
سؤال
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
سؤال
Which of the following problems can be programmed recursively?

A) Towers of Hanoi
B) Quicksort
C) Binary search
D) All of the above
سؤال
This term is used for methods that directly call themselves.

A) Direct recursion
B) Simple recursion
C) Absolute recursion
D) Native recursion
سؤال
In Java, it is not possible for a method to call itself.
سؤال
Recursive algorithms are usually less efficient than iterative algorithms.
سؤال
The part of a problem that is solved with recursion is known as the:

A) terminal case
B) final case
C) absolute case
D) recursive case
سؤال
Like ________, a recursive method must have some way to control the number of times it repeats.

A) a loop
B) any method
C) a class constructor
D) an event
سؤال
Unlike a loop, a recursive method does not require code to stop it from repeating.
سؤال
If method A calls method B, which in turn calls method A, it is called indirect recursion.
سؤال
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 Deck
1/42
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 16: Recursion
1
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 the:

A) recursive case
B) terminal case
C) base case
D) final case
C
2
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
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 depth of test2(18,5)?

A) 0
B) 1
C) 2
D) 3
C
4
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
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 depth of Test14(7)?

A) 0
B) 1
C) 6
D) 7
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
6
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
7
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
8
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
9
Recursion can be a powerful tool for solving:

A) basic problems
B) repetitive problems
C) object-oriented problems
D) binary problems
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
10
Usually, a problem is reduced by making the value of one or more parameters ________ with each recursive call.

A) larger
B) smaller
C) negative
D) equal
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
11
Recursive algorithms are usually less efficient than:

A) iterative algorithms
B) quantum algorithms
C) pseudocode algorithms
D) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
12
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
13
How many times will the following method call itself if the value 10 is passed as an 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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
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(18,5)?

A) 6
B) -5
C) 7
D) 1
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
15
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
16
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) The order in which the method appears on the stack
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
17
A recursive method is:

A) a method that accepts no arguments
B) a method that contains a static field
C) a method that calls itself
D) a method that has a loop
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
18
The actions that the JVM must perform any time a method is called are known as:

A) Stack depth
B) Overhead
C) Housekeeping
D) Method calls
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
19
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
20
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
21
Indirect recursion occurs when:

A) a loop is used to solve a recursive problem
B) a recursive method has no code to stop it from repeating
C) a method calls itself
D) a method calls itself from another method
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
22
A problem can be solved recursively if it can be broken down into successive smaller problems that are unique within the overall problem.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
23
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
24
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 nor B
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
25
If the base case in a recursive method is never reached:

A) the method will call itself only once
B) the result will always be off by one
C) the method will call itself indefinitely
D) the method will never call itself
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
26
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
27
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
28
Any problem that can be solved recursively can also be solved iteratively.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
29
How many times will the following method call itself if the value 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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
30
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
31
This type of method is a method that calls itself.

A) Looping
B) Circular
C) Recursive
D) Reoccurring
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
32
Indirect recursion occurs when a method calls another method that in turn calls the first method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
33
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
34
Which of the following problems can be programmed recursively?

A) Towers of Hanoi
B) Quicksort
C) Binary search
D) All of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
35
This term is used for methods that directly call themselves.

A) Direct recursion
B) Simple recursion
C) Absolute recursion
D) Native recursion
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
36
In Java, it is not possible for a method to call itself.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
37
Recursive algorithms are usually less efficient than iterative algorithms.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
38
The part of a problem that is solved with recursion is known as the:

A) terminal case
B) final case
C) absolute case
D) recursive case
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
39
Like ________, a recursive method must have some way to control the number of times it repeats.

A) a loop
B) any method
C) a class constructor
D) an event
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
40
Unlike a loop, a recursive method does not require code to stop it from repeating.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
41
If method A calls method B, which in turn calls method A, it is called indirect recursion.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
42
A problem can be solved recursively if it can be broken down into successive smaller problems that are identical to the overall problem.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 42 في هذه المجموعة.