Here is class 12 computer science Unit 6 [Type A] solutions for Sumita Arora back exercise assignment. Below includes both textual and video solutions wherever required. View all the answers in assignment for chapter 6 and for all chapters here.Watch all tutorials for chapter 6.
A recursive function is that which call itself again and again via self-referential expression till condition satisfies.
The major advantage is reduced time complexity and multiple iteration is reduced.
Direct recursion occurs when a method calls itself “directly” within its body under the need and condition.
Indirect recursion occur when a function is not called by itself but by other function.
For example if a function g calls g again during its cycle then it is direct recursion but whrn function g calls function f during cycle of recursion then it is indirect recursion.
The two cases are :(a) Base case(b) Recursive case
Base case: The condition under which recursion will occur and till it satisfy the case to be continued.
if n==1: #part 1 i.e. base case
Recursive case: Call of recursive function i.e. calling itself.
return factorial(n-1)*n # part2 i.e. recursive case
Yes, it is highly important as absence of base case will make recursion to run infinitely as the lack of stopping and staring condition.
Infinite recursion is the case of occurrence of the recursion infinite time.
This may can occur of several reasons:1. Absence or wrong base case.2. Not updating the case with each iteration.3. Improper logic implementation.
To stop/resolve an infinite recursion:1. Make sure presence of base case.2. Proper logic so that base case must be satisfied at proper time.
Some Examples of recursion are:
1. Factorial Number
if n == 0:
print("factorial of 18 is :", factorial(18))
2. Sum of n number
if n <1 :
print("Series sum of 100 is :", series_sum(100))
3. Fibonacci Series
if n <2 :
print("9th element of fibonacci series is :", fibonacci(9))
Yes, we can easily represent any program with recursion through iteration. The only need will be proper stack and manual calling of function again an again.
# by iteration method
for i in range(2,len(n)+1):
# by recursion method
Call by recursive method will result in infinite recursion if n==1 cases is fail or missing.
In the above case only n>0 is the recursive case and rest is the base cases or terminating case.
Recursive is slower than the iterative problem as the calling function need extra stack manipulation and in calling the function temporary variable are creates and need extra RAM space and increased time in its cycle.While in the iterative function no so such expensive routine is required to call the result.
Recursive function is required because in cases of larger instances and complexity large number of iterations are required and that easily can be done by the recursive function. Hence, it reduces the complexity at the provided condition.
We must give a push to the recursive approach where the problems are encountered with graphs and trees. As in this situation a stack of own will be created and this will be easily tackled by recursive function. And otherwise with limited iterations we must prefer the iterative function.
On the contrary of the speed Iterative perform faster than the recursive function.
On the contrary of the memory Recursive uses more memory than the iterative function.
Clear Doubts with Computer TutorIn case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in
You cannot copy content of this page