quiz1 Flashcards
Can you give an example of a problem that can be solved using recursion?
b.
Printing Fibonacci’s sequence
Recursion is implemented by the queue, and each time you invoke a method, the method is placed on top of the queue.
True
What is the focus of determining the order of growth?
a.
Dominant terms.
This method will return true only in case if:
public static boolean check (String s){
return s.length( ) >= 2 && (s.charAt(0) == s.charAt(1) || check(s.substring(1))); }
c.
The string s contains two or more of the same character that are next to each other.
How does the call stack work in relation to recursive functions?
a.
It keeps track of the function calls made
Which of the following is equivalent to 2n^3 + 5n^2 + 0.15n + 7 ≈ n^3?
a.
The order of growth of 2n^3 + 5n^2 + 0.15n + 7 is 2n^3.
The following function checks to see if the last item in a data set is higher or lower than the first item in a data set — and returns Higher, Lower, or Neither. What is its Big O?
a.
O(1)
How does a recursive function call itself?
d.
By using the function name
An example of logarithmic time complexity is:
a.
Binary search
What will Repeat(82, 3) return from the following method declaration?
public static int Repeat(int i, int j){
if (i==0)
return 0;
else
return Repeat(i/j, j)+1;
}
a.
6
Which of the following is true about the relationship between inputs and timers in calculating algorithm efficiency?
c.
Time varies for different inputs and can express a relationship.
What will be the output of the following code:
int factorial(int n) {
if(n == 0)
return 1;
else
return n * factorial(n-1);
}
int main() {
int number = 5;
cout«factorial(number);
return 0;
}
b.
120
Which of the statements below is not related to recursion
c.
Implementation of the selection statements
Which of the following factors does not affect the time complexity of an algorithm?
d.
The speed of the computer executing the algorithm
What is the limitation of calling recursion?
b.
limit of the heap memory