Deck 11: Recursion
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
سؤال
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/40
العب
ملء الشاشة (f)
Deck 11: Recursion
1
The recursive solution of the Towers of Hanoi problem has _______________ complexity.
A) exponential
B) polynomial
C) logarithmic
D) low
E) none of the above
A) exponential
B) polynomial
C) logarithmic
D) low
E) none of the above
A
Explanation: The recursive solution of the Towers of Hanoi problem has exponential complexity, which means that it is significantly inefficient.
Explanation: The recursive solution of the Towers of Hanoi problem has exponential complexity, which means that it is significantly inefficient.
2
A method that calls itself is a __________________ method.
A) invalid
B) static
C) final
D) recursive
E) public
A) invalid
B) static
C) final
D) recursive
E) public
D
Explanation: A recursive method is a method that calls itself.
Explanation: A recursive method is a method that calls itself.
3
Which of the following is a proper recursive definition of x raised to the y power?
A) xy = x*xy-1
B) xy = x*xy-2
C) xy = x*xy-1 for y > 1; xy = x for y = 1
D) xy = x*xy-1 for all x
E) none of the above
A) xy = x*xy-1
B) xy = x*xy-2
C) xy = x*xy-1 for y > 1; xy = x for y = 1
D) xy = x*xy-1 for all x
E) none of the above
C
Explanation: Choice c is correct because it has a properly defined base case.
Explanation: Choice c is correct because it has a properly defined base case.
4
A method that calls a different method, which then calls the original calling method is a recursive method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
5
Which of the following statements is true?
A) Recursion should be used in every program.
B) Recursion should be avoided all the time.
C) Solutions that are easily expressed recursively should be programmed recursively.
D) Solutions that are easily expressed recursively should be programmed iteratively.
E) None of the above.
A) Recursion should be used in every program.
B) Recursion should be avoided all the time.
C) Solutions that are easily expressed recursively should be programmed recursively.
D) Solutions that are easily expressed recursively should be programmed iteratively.
E) None of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
6
In the Towers of Hanoi puzzle __________________________________ .
A) it is legal to move a disk onto a peg that contains smaller disks.
B) it is legal to sit a disk aside, not on any peg.
C) it is illegal to move a disk onto a peg that contains only larger disks.
D) it is illegal to move a disk onto a peg that contains no other disks.
E) none of the above are true
A) it is legal to move a disk onto a peg that contains smaller disks.
B) it is legal to sit a disk aside, not on any peg.
C) it is illegal to move a disk onto a peg that contains only larger disks.
D) it is illegal to move a disk onto a peg that contains no other disks.
E) none of the above are true
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
7
In a recursive solution, _______________ is(are) always necessary.
A) short, efficient code
B) several variables
C) numerous lines of code
D) a base case
E) none of the above
A) short, efficient code
B) several variables
C) numerous lines of code
D) a base case
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
8
A solution with exponential complexity is ____________________ .
A) efficient
B) inefficient
C) easy to implement
D) difficult to implement
E) none of the above
A) efficient
B) inefficient
C) easy to implement
D) difficult to implement
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
9
In the Towers of Hanoi puzzle, there are ________________ pegs.
A) 2
B) 3
C) 4
D) 5
E) The Towers of Hanoi puzzle can include any number of pegs
A) 2
B) 3
C) 4
D) 5
E) The Towers of Hanoi puzzle can include any number of pegs
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
10
All recursive methods must have a base case.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
11
All recursive programs ____________________________________ .
A) are more difficult to read than iterative programs.
B) can be implemented iteratively.
C) are easier to read than iterative programs.
D) are shorter than iterative programs.
E) none of the above are true.
A) are more difficult to read than iterative programs.
B) can be implemented iteratively.
C) are easier to read than iterative programs.
D) are shorter than iterative programs.
E) none of the above are true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
12
There is(are) ____________ base case(s) in the recursive solution to finding a path through a maze.
A) 0
B) 1
C) 2
D) 3
E) 4
A) 0
B) 1
C) 2
D) 3
E) 4
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
13
Which of the following will result from infinite recursion in Java?
A) The program will hang as though there is an infinite loop.
B) The program will throw an ArrayOutOfBoundsException.
C) The program will not compile.
D) The program will run out of memory.
E) none of the above.
A) The program will hang as though there is an infinite loop.
B) The program will throw an ArrayOutOfBoundsException.
C) The program will not compile.
D) The program will run out of memory.
E) none of the above.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
14
In Java, it is possible for a method to call itself.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
15
The _______________________ puzzle is a favorite of computer scientists because of its elegant recursive solution.
A) Tower of Hanoi
B) Sudoku
C) Tetris
D) Tic-Tac-Toe
E) none of the above
A) Tower of Hanoi
B) Sudoku
C) Tetris
D) Tic-Tac-Toe
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
16
____________________ recursion occurs when a method calls itself, while _________________ recursion when a method calls another method that then calls the original method.
A) upward, downward
B) downward, upward
C) direct, indirect
D) indirect, direct
E) none of the above
A) upward, downward
B) downward, upward
C) direct, indirect
D) indirect, direct
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
17
Some problems can only be solved recursively.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
18
__________________ recursion results from the lack of a base case.
A) Indirect
B) Direct
C) Infinite
D) Spiral
E) none of the above
A) Indirect
B) Direct
C) Infinite
D) Spiral
E) none of the above
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
19
In the Towers of Hanoi puzzle there are __________________ disks of different diameters.
A) 2
B) 3
C) 4
D) 5
E) The Towers of Hanoi puzzle can include any number of disks of different diameters.
A) 2
B) 3
C) 4
D) 5
E) The Towers of Hanoi puzzle can include any number of disks of different diameters.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
20
Recursive solutions to problems should be used whenever possible.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
21
Write a recursive definition for K(n), which represents the product of all of the even integers less than or equal to n.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
22
Describe a recursive solution to the Towers of Hanoi puzzle with N disks.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
23
Describe a recursive solution to determine whether a String object is a palindrome. You may assume that the string only contains lower case characters (i.e. no numbers, spaces, punctuation, etc). Hint: It may be easiest to describe your solution using pseudocode.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
24
Describe the Towers of Hanoi puzzle.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
25
The Towers of Hanoi puzzle cannot be solved iteratively.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
26
A program with infinite recursion will act similarly to a program with an infinite loop.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
27
What is recursion?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
28
Write a recursive method that computes the sum of the first n integers.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
29
Write a recursive method that computes the product of all of the even integers less than or equal to n.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
30
Recursion is necessary.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
31
What is wrong with the following recursive method that computes the sum of all of the odd positive integers less than or equal to n?
public int sumOfOdds(int n) {
if(n%2 == 0)
return sumOfOdds(n-1);
else
return n + sumOfOdds(n-2);
}
public int sumOfOdds(int n) {
if(n%2 == 0)
return sumOfOdds(n-1);
else
return n + sumOfOdds(n-2);
}
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
32
Write a recursive Java method that takes in a String as a parameter and returns true if the String is a palindrome. You may assume that the string only contains lower case characters (i.e. no numbers, spaces, punctuation, etc).
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
33
The Fibonacci sequence is defined as the sum of the two previous elements of the sequence, with the first and second numbers in the sequence being 0 and 1 respectively. Write a recursive method that computes the nth Fibonacci number.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
34
In the Towers of Hanoi puzzle, it is legal to move a larger disk to a peg that already contains a smaller disk.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
35
Write the recursive definition of the factorial of a number.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
36
Give a recursive definition of the sum of the first n integers, S(n).
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
37
What are the "base" cases when searching for a path through a maze?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
38
Determining whether or not there is a path through a maze has a recursive solution.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
39
The Fibonacci sequence is defined as the sum of the two previous elements of the sequence, with the first and second numbers in the sequence being 0 and 1 respectively. Write a recursive mathematical definition of the Fibonacci numbers.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck
40
Write a recursive method that returns the factorial of an integer.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 40 في هذه المجموعة.
فتح الحزمة
k this deck