Recursion/Iteration Flashcards

1
Q

What is iteration and recursion an example of?

A

traversal

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

What is the difference between indirect and direct iterators?

A

Direct iterator traverses throw the actual data while the indirect iterator traverses through instances of the data structure

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

What is the purpose of recursion?

A

To make the code simpler

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

what happens after a recursive call?

A

The method clones itself: copied,
local variables
parameters
code

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

What does the base case prevent?

A

Infinite recursion

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

What is Iterable?

A

an interface in java.lang

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

What method must be implemented when using Iterable?

A

Iterator(), which returns an iterator object for traversing through a list: Iterator = list.iterator()

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

What is Iterator?

A

An interface in java.util

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

What method must be implemented when using Iterator?

A
  • hasNext
  • next
  • remove(optional)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the fields for an indirect iterator class?

A
  1. ) A separate list data structure

2. ) Current position index

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

What are the fields for a direct iterator class?

A
  1. ) The fields that a list has
    - an array
    - numItems

2.)Current position index

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

Where is the reference of recursive method after a recursive call & base case detection?

A

after the recursive call, and before the condition, respectively

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

Where are the clones stored?

A

In the stack in the activation records

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

Once the method returns and breaks recursive chain what happens to the current method?

A

It disappears

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

What is the address of a method before the return address?

A

System

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

What structure can be used when two recursive calls are added/connotated?

A

A binary tree

17
Q

What two methods can be used to analyze runtime of a recursive function?

A
  1. ) informal reasoning

2. )recurrence equation

18
Q

What are the components of a recurrence equation?

A

T(N) + A + C(T(N))
A:time outside of recursive call
C: # recursive calls
N: problem size

19
Q

How do you find the worst case complexity of a recurrence function?

A

finding the closed form solution to the recurrence equation

20
Q

What are the steps to fond the closed form of a R.E?

A

make a T(N) vs. N table including the base case
look for pattern in terms of just N
verify by plugging function into T(N) in recurrence equation