function Flashcards

1
Q

return a,b
is it correct or is it gives error

A

correct
it returns multiple value i.e. a and b

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

when recursive call is made then ____________ will be created in _________________

A

when recursive call is made then activation record will be created in stack

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

Syntax to create user defined functions

A

def function_name(parameters):
statement1
statement2
:
return value

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

give example of tail recursion

A

def tail_rec(n):
if n==0:
return
else:
print(n)
return tail_rec(n-1)

tail_rec(4)

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

tail recursion

A

In the program the very last statement is the only one recursive call and there is no other statement after that then it is called as tail recursion

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

non-tail recursion

A

in the program after the recursive call some statements to execute, then it is called non-tail recursion

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

recursion

A

function calling itself is called recursion

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

tell the error

def summation(a,b):
summation = a+b
return a,b

A

no error

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

Function calling itself is called __________

A

recursion

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

is ‘def’ required to create function

A

yes, required

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

def wish():
print(‘Good evening’)
print(‘hey we are in function’)

for i in range(3):
wish()

A

Good evening
hey we are in function
Good evening
hey we are in function
Good evening
hey we are in function

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

if recursion doesn’t have termination condition, it will leads to _______________________

A

stack overflow

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

types of functions

A

1.)Built-in functions
2.)User defined functions

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

Recursion function should have _____________ condition

A

termination or base

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

how can we write equivalent non recursive program of tail recursion

A

by using loops

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

Main advantage of functions

A

Code reusability

17
Q

example of non tail recursion

A

def nt(n):
if n<=1:
return
else:
nt(n-2)
print(n)
nt(n-1)
print(n-2)

18
Q

is ‘return’ required to create function

A

No
return is optional

19
Q

in the program after the recursive call some statements to execute, then it is called

A

non-tail recursion

20
Q

can we write equivalent non recursive program of tail recursion

A

yes by using loops

21
Q

types of recursion

A

4 types
1.)tail recursion
2.)non-tail recursion
3.)indirect recursion
4.)nested recursion

22
Q

recursion internally uses _______________ data structure

A

stack

23
Q

can we write equivalent non recursive program of non tail recursion

A

yes but it is very difficult

24
Q

stack overflow

A

if recursion doesn’t have termination condition, it will leads to stack overflow

25
Q

another name of ‘termination condition’

A

base condition

26
Q

Activation record

A

the stack frame(memory) allocated to the recursive function call as activation record.
The creation and deletion of activation record depends on actual function calling sequence

27
Q

special thing about ‘return’ of python which separates it from other languages

A

in python: a function can return any number of values
in other languages: a function return almost one value

28
Q

keywords uses when we create function

A

def
return

29
Q

Indirect recursion

A

The two or more functions calling each other is called indirect recursion

30
Q

Nested Recursion

A

A recursion function which is passing itself as parameter to a recursive call is called as nested recursion

31
Q

__name__

A

It is special variable in python which will be added internally. This variable stores information regarding whether the program is executed as individual program or as a module

32
Q

explain the value of __name__

A

if the __name__ = __main__ then the program is executed as individual
if the __name != __main__ then the program is executed as module and __name__ will return the name of module where it is defined