Python Test 7 - Recursion 1. Which is the most appropriate definition for recursion?A function execution instance that calls another execution instance of the same functionA function that calls itselfA class method that calls another class methodAn in-built method that is automatically called Only problems that are recursively defined can be solved using recursion.FalseTrue Which of these is false about recursion?Recursive functions run faster than non-recursive functionRecursion makes programs easier to understandRecursive functions usually take more memory space than non-recursive functionRecursive function can be replaced by a non-recursive function Fill in the line of the following Python code for calculating the factorial of a number. def fact(num): if num == 0: return 1 else: return _____________________fact(num)*fact(num-1)num*(num-1)(num-1)*(num-2)num*fact(num-1) What will be the output of the following Python code? def test(i,j): if(i==0): return j else: return test(i-1,i+j) print(test(4,7))13177Infinite loop What will be the output of the following Python code? l=[] def convert(b): if(b==0): return l dig=b%2 l.append(dig) convert(b//2) convert(6) l.reverse() for i in l: print(i,end="")1100113Infinite loop What is tail recursion?A function where the recursive functions leads to an infinite loopA recursive function that has two base casesA function where the recursive call is the last thing executed by the function View AnswerA recursive function where the function doesn’t return anything and just prints the values Observe the following Python code? def a(n): if n == 0: return 0 else: return n*a(n - 1) def b(n, tot): if n == 0: return tot else: return b(n-2, tot-2)Both a() and b() are tail recursiveBoth a() and b() aren’t tail recursivea() is tail recursive but b() isn’tb() is tail recursive but a() isn’t Which of the following statements is false about recursion?Every recursive function must have a return valueA recursive function makes the code easier to understandInfinite recursion can occur if the base case isn’t properly mentionedEvery recursive function must have a base case What will be the output of the following Python code? def fun(n): if (n > 100): return n - 5 return fun(fun(n+11)); print(fun(45))5010074Infinite loop Recursion and iteration are the same programming approach.TrueFalse What happens if the base condition isn’t defined in recursive programs?Program runs n number of times where n is the argument given to the functionAn exception is thrownProgram runs onceProgram gets into an infinite loop Which of these is not true about recursion?Sequence generation is easier than a nested iterationA complex task can be broken into sub-problemsRecursive calls take up less memoryMaking the code look clean Which of these is not true about recursion?Recursive functions are easy to debugThe logic behind recursion may be hard to followPrograms using recursion take longer time than their non-recursive equivalentRecursive calls take up a lot of memory What will be the output of the following Python code? def a(n): if n == 0: return 0 elif n == 1: return 1 else: return a(n-1)+a(n-2) for i in range(0,4): print(a(i),end=" ")0 1 1 2 30 1 1 20 1 2 3An exception is thrown Schreibe einen Kommentar Antworten abbrechenDu musst angemeldet sein, um einen Kommentar abzugeben.