Recursion and Iteration Flashcards

1
Q

what is the call stack

A

s stack maintained by the java runtime system

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

what does each call stack frame contain

A

all information necessary to execute the method eg

parameter values and local objects, return addresses etc

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

where are objects stored in memory

A

heap

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

every time a new method is called, what happens to the stack

A

a new stack frame is pushed on

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

every time a method returns, what happens in the stack

A

the topmost stack frame is popped

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

what is recursion

A

when something is defined in terms of itself

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

when is a method recursive

A

when it calls itself

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

how does the stack decide how much memory is needed for a method

A

uses largest case

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

why can a stack not handle infinite recursion

A

impossible to fix a memory amount to this

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

what happens when the stack recognises infinite recursion

A

exception thrown

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

how to calculate the asymptotic worst case running time of a recursive algorithm

A

recursive calls * cost of each call

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

how to calculate memory needed for a recursive algorithm

A

max # of active frames on call stack at the one time

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

what is an accumulator in recursion

A

a way of communicating a partial result down through the recursive call chain

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

what is tail recursion

A

needs value from the previous recursion to continue

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

does tail recursion use more or less stack frames

A

less

as every function returns, not lots of active frames at once

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

which is better for memory usage:
iteration
recursion

A

iteration