Deck 15: Recursion
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/34
العب
ملء الشاشة (f)
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
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
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
{
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.
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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
{
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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.
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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.
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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
{
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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.
A) stack frame.
B) overhead.
C) housekeeping.
D) method calls.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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
{
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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
A) a mathematical game
B) often used in computer science textbooks
C) demonstrates the power of recursion
D) All of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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
{
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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.
A) the recursive case.
B) the terminal case.
C) the base case.
D) the final case.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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
{
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
k this deck
21
This type of method is a method that calls itself.
A) Looping
B) Circular
C) Recursive
D) Reoccurring
A) Looping
B) Circular
C) Recursive
D) Reoccurring
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
k this deck
22
Recursive algorithms are usually less efficient than iterative algorithms.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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
A) a loop
B) any method
C) a GUI method
D) a rumor
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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
A) terminal case
B) final case
C) re-occurring case
D) recursive case
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
k this deck
27
If Method A calls Method B which in turn calls Method A,it is called indirect recursion.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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
{
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
k this deck
30
Any problem that can be solved recursively can also be solved iteratively.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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
A) height of recursion
B) depth of recursion
C) width of recursion
D) length of recursion
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
k this deck
33
Indirect recursion occurs when a method calls another method that in turn calls the first method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 34 في هذه المجموعة.
فتح الحزمة
k this deck