Chapter 22: Recursion Flashcards

1
Q

What is an anonymous array?

A

We can avoid declaring a variable to reference an array by providing a list of the elements.
New Type[] {value, value, value}

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

What is a private constructor method?

A
Constructors are public because we want to permit other classes to construct objects.
Occasionally we want the creation of objects to be tightly controlled by the class itself.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is recursion?

A

Something is defined in terms of itself

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

What is a recursive algorithm?

A

Algorithm: procedure for undertaking some class.
Recursive: expressed in terms of itself

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

How do we design a recursive algorithm?

A
  1. Base cases- when is the problem solved easily
  2. Recursive cases- an occurrence of the problem of the same kind but simpler.
  3. The solution of the simpler problem helps to solve the given one
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a recursive method?

A

One that contains one or more method call to itself. Any route not containing a recursive call is the base case

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

What are two common misunderstandings?

A

A recursive method call makes execution go back to the beginning: It starts another separate occurrence of the method
There is one copy of each method variable belonging to a method: Each call creates a new set of method variables to be used in that execution

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

What makes a recursive algorithm well defined?

A

Clearly identified range of arguments for which it is meant to work
At least one base case that doesn’t make a recursive call
In all recursive cases, arguments passed to the call are nearer to the base case than those given.

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

Describe the difference between recursion and iteration

A

Many recursive methods could be easily implemented by iteration. Iteration is an optimized implementation of tail recursion

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

What is tail recursion?

A

There is no more work to do after the recursive call has been made

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

What is multiple recursion?

A

The activation of a method can cause more than one recursive activation of the same method. Hard to express iteratively

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

What is a recursive data structure?

A

A data structure that consists of objects containing a reference to other objects of the same type i.e. binary trees

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