Recursion Flashcards

1
Q

What is recursion

A

A function calling itself

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

Which DS is used to solve recursion

A

STACK

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

Every function call has its own?

A

Stack space and local variables

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

If no termination condition present in recursive program then what happens

A

Stack overflow which is a runtime error

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

For every recursive program, is non recursive program present?

A

Yes

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

Time complexity comparison of recursive and non recursive program for same algo

A

Same

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

Space complexity comparison of recursive and non recursive program for same algo

A

Space complexity of recursive program is more

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

Amount of stack space used by recursive program

A

Depth of stack

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

From one call to another call of a recursive prog does code, no. of parameters, name of parameter change?

A

No only value of parameters can change

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

Methods for solving recursive problems

A

Substitution, Recursive tree, Masters theorem

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

Constant time corresponds to

A

O(1)

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

For multiplication by recursion no. of additions for doing m*n

A

0 if m=0 or n=0
A(m,n-1)+1 if n>0 and m>0

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

For fibonacci series nth no., no. of additions

A

0 if n=0 or n=1(n<=1)
fib(n-1)+fib(n-2)+1

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

Substitution

A

Substitute until u get a pattern

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

1+2+3+—–+n

A

n(n+1)/2

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

123—–n

A

n!

16
Q

Sum of squares of natural nos.

A

n(n+1)(2n+1)/6

17
Q

Which log considered in TC

A

log base 2

18
Q

(log n)^2

A

log^2 n

19
Q

In infinite loop , why is there no stack overflow

A

Because only one function call

20
Q

AGP solve method

A

FInd T(n)
Find 2T(n)
Do T(n)-2T(n)
Find -T(n)

21
Q

Recursive tree

A

Find leftmost length, rightmost length and then evaluate upper and lower bounds

22
Q

Tree height in recursive tree

A

Stack space is tree height

23
Q
A
23
Q

Decreasing GP value gives

A

O(1)

24
Q

Log property a ^ log b c

A

= c ^ log b a

25
Q
A