Deck 3: Recursion: the Mirrors

ملء الشاشة (f)
exit full mode
سؤال
A recursive method that computes the number of groups of k out of n things has the precondition that ______.

A)n is a positive number and k is a nonnegative number
B)n is a nonnegative number and k is a positive number
C)n and k are nonnegative numbers
D)n and k are positive numbers
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
A ______ is a mathematical formula that generates the terms in a sequence from previous terms.

A)local environment
B)pivot item
C)base case
D)recurrence relation
سؤال
The factorial of zero is ______.

A)-1
B)0
C)1
D)2
سؤال
What would happen if a negative value is passed to a method that returns the factorial of the value passed to it?

A)the method will calculate the correct value for the factorial of the number
B)the method will calculate a negative value for the factorial of the number
C)the method would terminate immediately
D)an infinite sequence of recursive calls will occur
سؤال
In the box trace for a recursive method,a new box is created each time ______.

A)the method is called
B)the method returns a value
C)the object is created
D)the object is initialized
سؤال
In a recursive method that writes a string of characters in reverse order,the base case is ______.

A)a string with a length of 0
B)a string whose length is a negative number
C)a string with a length of 3
D)a string that is a palindrome
سؤال
Which of the following is NOT a precondition for an array that is to be sorted by a recursive binary search algorithm? (first is the index of the first item in the array,last is the index of the last item in the array,and SIZE is the maximum size of the array)

A)SIZE <= first
B)0 <= first
C)last <= SIZE - 1
D)anArray[first] <= anArray[first + 1] <= … <= anArray[last]
سؤال
How many bases cases will be required in a recursive solution that solves a problem by solving two smaller problems of the same type?

A)0
B)1
C)2
D)3
سؤال
A class method is defined as ______.

A)static
B)abstract
C)private
D)protected
سؤال
The base case for a recursive definition of the factorial of n is ______.

A)factorial (-1)
B)factorial (0)
C)factorial (1)
D)factorial (n - 1)
سؤال
The factorial of n is equal to ______.

A)n - 1
B)n - factorial (n-1)
C)factorial (n-1)
D)n * factorial (n-1)
سؤال
If the value being searched for by a recursive binary search algorithm is in the array,which of the following is true?

A)the algorithm cannot return a nonpositive number
B)the algorithm cannot return a nonnegative number
C)the algorithm cannot return a zero
D)the algorithm cannot return a negative number
سؤال
When you solve a problem by solving two or more smaller problems,each of the smaller problems must be ______ the base case than the original problem.

A)closer to
B)farther to
C)either closer to or the same "distance" from
D)either farther to or the same "distance" from
سؤال
The midpoint of a sorted array can be found by ______,where first is the index of the first item in the array and last is the index of the last item in the array.

A)first / 2 + last / 2
B)first / 2 - last / 2
C)(first + last)/ 2
D)(first - last)/ 2
سؤال
An array is a(n)______.

A)class
B)method
C)object
D)variable
سؤال
In a recursive solution,the ______ terminates the recursive processing.

A)local environment
B)pivot item
C)base case
D)recurrence relation
سؤال
In the box trace,each box roughly corresponds to a(n)______.

A)recursive relation
B)activation record
C)base case
D)pivot item
سؤال
In the box trace,each box contains all of the following EXCEPT ______.

A)the values of the references and primitive types of the method's arguments
B)the method's local variables
C)the method's class variables
D)a placeholder for the value returned by each recursive call from the current box
E)the value of the method itself
سؤال
Which of the following is a precondition for a method that accepts a number n and computes the nth Fibonacci number?

A)n is a negative integer
B)n is a positive integer
C)n is greater than 1
D)n is an even integer
سؤال
The number of ways to choose k out of n things is ______.

A)the number of ways to choose k - 1 out of n - 1 things
B)the number of ways to choose k out of n - 1 things
C)the sum of the number of ways to choose k - 1 out of n - 1 things and the number of ways to choose k out of n - 1 things
D)the product of the number of ways to choose k - 1 out of n - 1 things and the number of ways to choose k out of n - 1 things
سؤال
A recursive solution can have more than one base cases.
سؤال
In the recursive solution to the Towers of Hanoi problem,the number of disks to move ______ at each recursive call.

A)decreases by 1
B)increases by 1
C)decreases by half
D)increases by half
سؤال
The binary search algorithm can be applied to an unsorted array.
سؤال
A recursive solution that finds the factorial of n generates ______ recursive calls.

A)n-1
B)n
C)n+1
D)n*2
سؤال
In the Fibonacci sequence,which of the following integers comes after the sequence 1,1,2,3?

A)3
B)4
C)5
D)6
سؤال
An iterative method always calls itself.
سؤال
Every recursive method must have a base case.
سؤال
When constructing a recursive solution,you should assume that a recursive call's postcondition is true if its precondition is true.
سؤال
The base case for a recursive solution to the kth smallest item problem cannot be predicted in advance.
سؤال
A recursive solution solves a problem by solving a smaller instance of the same problem.
سؤال
A binary search starts at the beginning of the collection of items.
سؤال
For anArray = <2,3,5,6,9,13,16,19>,what is the value returned by a recursive binary search algorithm if the value being searched for is 10?

A)-1
B)0
C)1
D)10
سؤال
A recursive solution that finds the factorial of n always reduces the problem size by ______ at each recursive call.

A)1
B)2
C)half
D)one-third
سؤال
In the recursive solution to the kth smallest item problem,the problem size decreases by ______ at each recursive call.

A)1
B)at least 1
C)half
D)at least half
سؤال
A recursive binary search algorithm always reduces the problem size by ______ at each recursive call.

A)1
B)2
C)half
D)one-third
سؤال
A method that is declared as static is an object method.
سؤال
In a sorted array,the kth smallest item is given by ______.

A)anArray[k-1]
B)anArray[k]
C)anArray[SIZE-k]
D)anArray[SIZE+k]
سؤال
An iterative solution involves loops.
سؤال
For anArray = <2,3,5,6,9,13,16,19>,what is the value returned by a recursive binary search algorithm if the value being searched for is 6?

A)1
B)3
C)4
D)6
سؤال
Which of the following is a base case for a recursive binary search algorithm? (first is the index of the first item in the array,last is the index of the last item in the array,and mid is the midpoint of the array).

A)last > first
B)first > last
C)0 <= first
D)last <= SIZE-1
سؤال
Why do some compilers automatically replace tail recursion with iteration?
سؤال
What are the two factors which contribute to the inefficiency of some recursive solutions?
سؤال
What is the box trace?
سؤال
What is the base case for the recursive solution to the Towers of Hanoi problem?
سؤال
What is an activation record?
سؤال
Why does the Fibonacci sequence have two base cases? In other words,would it be possible to write a correct recursive Fibonacci method that has only one base case?
سؤال
Write a recursive method that takes 3 parameters: an integer array a,and two integers first and last.The method will find the largest value in a between indices first and last,inclusive.That is,it will return the largest value in the part of the array a[first..last] .You may assume that first  last.
سؤال
How does a sequential search work?
سؤال
What is a tail-recursive method?
سؤال
Suppose a program contains a recursive method findFibonacci(int n),which computes the n-th Fibonacci number.Even if we know that a client method will never call findFibonacci( )with the values 1 or 2 as arguments,why does the implementation of findFibonacci( )still need to have base cases?
سؤال
What is a base case?
سؤال
What are the four questions that must be considered when constructing a recursive solution?
سؤال
When is the base case value == anArray[mid] (where mid is the midpoint of the array)reached in a recursive binary search algorithm?
سؤال
When is the base case first > last (where first is the index of the first item in the array and last is the index of the last item in the array)reached in a recursive binary search algorithm?
سؤال
What elements are included in a method's local environment?
سؤال
What is a pivot item?
سؤال
Suppose sa is a sorted array of integer values,and we wish to search for a number target in this array.If sa contains n elements,and we use the binary search strategy,what is the approximate maximum number of comparisons necessary to determine that the value target is or is not in the array? How would your answer change if the array were not sorted?
سؤال
Write a recursive method that takes a String parameter and prints out the characters of the string in reverse order.
سؤال
What is a recurrence relation?
سؤال
What are the two base cases for a recursive binary search algorithm?
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/60
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 3: Recursion: the Mirrors
1
A recursive method that computes the number of groups of k out of n things has the precondition that ______.

A)n is a positive number and k is a nonnegative number
B)n is a nonnegative number and k is a positive number
C)n and k are nonnegative numbers
D)n and k are positive numbers
C
2
A ______ is a mathematical formula that generates the terms in a sequence from previous terms.

A)local environment
B)pivot item
C)base case
D)recurrence relation
D
3
The factorial of zero is ______.

A)-1
B)0
C)1
D)2
C
4
What would happen if a negative value is passed to a method that returns the factorial of the value passed to it?

A)the method will calculate the correct value for the factorial of the number
B)the method will calculate a negative value for the factorial of the number
C)the method would terminate immediately
D)an infinite sequence of recursive calls will occur
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
5
In the box trace for a recursive method,a new box is created each time ______.

A)the method is called
B)the method returns a value
C)the object is created
D)the object is initialized
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
6
In a recursive method that writes a string of characters in reverse order,the base case is ______.

A)a string with a length of 0
B)a string whose length is a negative number
C)a string with a length of 3
D)a string that is a palindrome
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
7
Which of the following is NOT a precondition for an array that is to be sorted by a recursive binary search algorithm? (first is the index of the first item in the array,last is the index of the last item in the array,and SIZE is the maximum size of the array)

A)SIZE <= first
B)0 <= first
C)last <= SIZE - 1
D)anArray[first] <= anArray[first + 1] <= … <= anArray[last]
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
8
How many bases cases will be required in a recursive solution that solves a problem by solving two smaller problems of the same type?

A)0
B)1
C)2
D)3
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
9
A class method is defined as ______.

A)static
B)abstract
C)private
D)protected
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
10
The base case for a recursive definition of the factorial of n is ______.

A)factorial (-1)
B)factorial (0)
C)factorial (1)
D)factorial (n - 1)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
11
The factorial of n is equal to ______.

A)n - 1
B)n - factorial (n-1)
C)factorial (n-1)
D)n * factorial (n-1)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
12
If the value being searched for by a recursive binary search algorithm is in the array,which of the following is true?

A)the algorithm cannot return a nonpositive number
B)the algorithm cannot return a nonnegative number
C)the algorithm cannot return a zero
D)the algorithm cannot return a negative number
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
13
When you solve a problem by solving two or more smaller problems,each of the smaller problems must be ______ the base case than the original problem.

A)closer to
B)farther to
C)either closer to or the same "distance" from
D)either farther to or the same "distance" from
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
14
The midpoint of a sorted array can be found by ______,where first is the index of the first item in the array and last is the index of the last item in the array.

A)first / 2 + last / 2
B)first / 2 - last / 2
C)(first + last)/ 2
D)(first - last)/ 2
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
15
An array is a(n)______.

A)class
B)method
C)object
D)variable
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
16
In a recursive solution,the ______ terminates the recursive processing.

A)local environment
B)pivot item
C)base case
D)recurrence relation
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
17
In the box trace,each box roughly corresponds to a(n)______.

A)recursive relation
B)activation record
C)base case
D)pivot item
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
18
In the box trace,each box contains all of the following EXCEPT ______.

A)the values of the references and primitive types of the method's arguments
B)the method's local variables
C)the method's class variables
D)a placeholder for the value returned by each recursive call from the current box
E)the value of the method itself
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
19
Which of the following is a precondition for a method that accepts a number n and computes the nth Fibonacci number?

A)n is a negative integer
B)n is a positive integer
C)n is greater than 1
D)n is an even integer
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
20
The number of ways to choose k out of n things is ______.

A)the number of ways to choose k - 1 out of n - 1 things
B)the number of ways to choose k out of n - 1 things
C)the sum of the number of ways to choose k - 1 out of n - 1 things and the number of ways to choose k out of n - 1 things
D)the product of the number of ways to choose k - 1 out of n - 1 things and the number of ways to choose k out of n - 1 things
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
21
A recursive solution can have more than one base cases.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
22
In the recursive solution to the Towers of Hanoi problem,the number of disks to move ______ at each recursive call.

A)decreases by 1
B)increases by 1
C)decreases by half
D)increases by half
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
23
The binary search algorithm can be applied to an unsorted array.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
24
A recursive solution that finds the factorial of n generates ______ recursive calls.

A)n-1
B)n
C)n+1
D)n*2
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
25
In the Fibonacci sequence,which of the following integers comes after the sequence 1,1,2,3?

A)3
B)4
C)5
D)6
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
26
An iterative method always calls itself.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
27
Every recursive method must have a base case.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
28
When constructing a recursive solution,you should assume that a recursive call's postcondition is true if its precondition is true.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
29
The base case for a recursive solution to the kth smallest item problem cannot be predicted in advance.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
30
A recursive solution solves a problem by solving a smaller instance of the same problem.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
31
A binary search starts at the beginning of the collection of items.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
32
For anArray = <2,3,5,6,9,13,16,19>,what is the value returned by a recursive binary search algorithm if the value being searched for is 10?

A)-1
B)0
C)1
D)10
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
33
A recursive solution that finds the factorial of n always reduces the problem size by ______ at each recursive call.

A)1
B)2
C)half
D)one-third
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
34
In the recursive solution to the kth smallest item problem,the problem size decreases by ______ at each recursive call.

A)1
B)at least 1
C)half
D)at least half
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
35
A recursive binary search algorithm always reduces the problem size by ______ at each recursive call.

A)1
B)2
C)half
D)one-third
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
36
A method that is declared as static is an object method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
37
In a sorted array,the kth smallest item is given by ______.

A)anArray[k-1]
B)anArray[k]
C)anArray[SIZE-k]
D)anArray[SIZE+k]
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
38
An iterative solution involves loops.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
39
For anArray = <2,3,5,6,9,13,16,19>,what is the value returned by a recursive binary search algorithm if the value being searched for is 6?

A)1
B)3
C)4
D)6
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
40
Which of the following is a base case for a recursive binary search algorithm? (first is the index of the first item in the array,last is the index of the last item in the array,and mid is the midpoint of the array).

A)last > first
B)first > last
C)0 <= first
D)last <= SIZE-1
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
41
Why do some compilers automatically replace tail recursion with iteration?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
42
What are the two factors which contribute to the inefficiency of some recursive solutions?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
43
What is the box trace?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
44
What is the base case for the recursive solution to the Towers of Hanoi problem?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
45
What is an activation record?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
46
Why does the Fibonacci sequence have two base cases? In other words,would it be possible to write a correct recursive Fibonacci method that has only one base case?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
47
Write a recursive method that takes 3 parameters: an integer array a,and two integers first and last.The method will find the largest value in a between indices first and last,inclusive.That is,it will return the largest value in the part of the array a[first..last] .You may assume that first  last.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
48
How does a sequential search work?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
49
What is a tail-recursive method?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
50
Suppose a program contains a recursive method findFibonacci(int n),which computes the n-th Fibonacci number.Even if we know that a client method will never call findFibonacci( )with the values 1 or 2 as arguments,why does the implementation of findFibonacci( )still need to have base cases?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
51
What is a base case?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
52
What are the four questions that must be considered when constructing a recursive solution?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
53
When is the base case value == anArray[mid] (where mid is the midpoint of the array)reached in a recursive binary search algorithm?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
54
When is the base case first > last (where first is the index of the first item in the array and last is the index of the last item in the array)reached in a recursive binary search algorithm?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
55
What elements are included in a method's local environment?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
56
What is a pivot item?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
57
Suppose sa is a sorted array of integer values,and we wish to search for a number target in this array.If sa contains n elements,and we use the binary search strategy,what is the approximate maximum number of comparisons necessary to determine that the value target is or is not in the array? How would your answer change if the array were not sorted?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
58
Write a recursive method that takes a String parameter and prints out the characters of the string in reverse order.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
59
What is a recurrence relation?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
60
What are the two base cases for a recursive binary search algorithm?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 60 في هذه المجموعة.