quiz1 Flashcards

1
Q

Can you give an example of a problem that can be solved using recursion?

A

b.
Printing Fibonacci’s sequence

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Recursion is implemented by the queue, and each time you invoke a method, the method is placed on top of the queue.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the focus of determining the order of growth?

A

a.
Dominant terms.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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))); }

A

c.
The string s contains two or more of the same character that are next to each other.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How does the call stack work in relation to recursive functions?

A

a.
It keeps track of the function calls made

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which of the following is equivalent to 2n^3 + 5n^2 + 0.15n + 7 ≈ n^3?

A

a.
The order of growth of 2n^3 + 5n^2 + 0.15n + 7 is 2n^3.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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

a.
O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How does a recursive function call itself?

A

d.
By using the function name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

An example of logarithmic time complexity is:

A

a.
Binary search

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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

a.
6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which of the following is true about the relationship between inputs and timers in calculating algorithm efficiency?

A

c.
Time varies for different inputs and can express a relationship.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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;

}

A

b.
120

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Which of the statements below is not related to recursion

A

c.
Implementation of the selection statements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which of the following factors does not affect the time complexity of an algorithm?

A

d.
The speed of the computer executing the algorithm

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the limitation of calling recursion?

A

b.
limit of the heap memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

The run time of algorithms is expressed in Big O notation.

A

False

17
Q

When the function with loops or recursive calls can have constant complexity?

A

c.
Number of iterations or calls independent of input size

18
Q

Order of growth focuses on lower-order terms.

A

False

19
Q

What are some potential causes of variations in timers?

A

a.
All answers are correct

20
Q

What does it mean for a problem to have complexity independent of inputs?

A

a.
The complexity of the problem remains constant no matter how many inputs are given.