Lec 7: Loops and Recursion Flashcards

1
Q

What is the syntax of a do loop

A

do{
Statement(s);
} while (condition);

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

What are 2 examples of infinitely running loops?

A

for(; ; ){} and while(true){}

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

What does continue do in a loop?

A

Immediately ends that loop run and goes for a new run

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

What is the number of iterations for
for (int i = 1; i < n; n++){
//iteration
}

A

n - 1

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

True or false: Every recursive method must have a base case or a stopping condition

A

True

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

True or false: A recursive method is invoked differently from a non-recursive method

A

False

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

True or false: Every recursive method must have a return value

A

False

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

What error happens when a recursive method doesn’t eventually get to a solution?

A

StackOverFlow

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

In the following method, what is the base case?
static int xMethod(int n){
if (n==1){
return 1;
}else{
return n + xMethod(n-1)}
}

A

n == 1

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

True or false: Recursive methods take more memory space than non-recursive methods

A

True

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

True or false: recursive methods run faster than non-recursive methods

A

False

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

True or false: A recursive method can always be replaced by a non-recursive method

A

True

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