recursion Flashcards

1
Q

what is a recursive function

A

a function that calls itself

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

base case

A

the condition that stops the recursion

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

recursive case

A

what the recursion is doing

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

why is the base case important

A

it stops the function from continuing infinitely which would be bad as it would eventually cause stack overflow

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

why do we need recursion in haskell

A

it is purely functional and enforces immutability therefore we wouldn’t be able to change i in a for loop

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

head recursion

A

each recursive call waits for the next call
cant get any actual value until the base case has been reached

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

what are negatives of head recursion

A

deep stack usage
large inputs can lead to stack overflow

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

what makes a function tail recursive

A

the recursive call is the last operation in the function

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

how does tail recursion work

A

each time the function is called the result gets accumulated

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

what are two benefits of tail recursion

A

the same stack frame can be used instead of creating new ones
optimises memory usage by avoiding deep stack calls

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