<jupyter_start><jupyter_text>Recursion- A way of solving a problem by having a function call itself. Performing the same operation with different inputs. Usually smaller inputs for convergence, with a base condition to prevent infinite loop.       IRL example- Russian Doll. Pseudocode<jupyter_code>def openRussianDoll(doll):
  if doll==1: #Smallest Doll
    print('All Dolls opened')
  else:
    openRussianDoll(doll-1)<jupyter_output><empty_output><jupyter_text>Recursion logic.Stack Memory is used and last in, first out is followed.                        Recursion is less time and space efficient as against iteration. But it is easier to code. How to write Recursion Factorial<jupyter_code>def factorial(n):
  assert n>=0 and int (n)==n, 'The number must be positive integer only'
  if n in [0,1]:
    return 1
  else:
    return n*factorial(n-1)
factorial(5)<jupyter_output><empty_output><jupyter_text>Fibonnaci n-th term of a Fibonnaci series<jupyter_code>fib_list=[]
def fibonacci(n):
  assert n>=0 and int (n) ==n, 'The number must be integer and positive'
  if n in [0,1]:
    return n
  else:
    return fibonacci(n-1)+fibonacci(n-2)
fibonacci(5)<jupyter_output><empty_output><jupyter_text>Fibonacci series containing of n terms<jupyter_code>a=0 
b=1
fib_list=[0,1]
n= int(input('No of terms you want'))
assert int (n)==n and n>0
i=0
if n==1:
  print(0)
else:
  while i<n-2:
    temp=a+b
    fib_list.append(temp)
    a=b
    b=temp
    i+=1
  print(fib_list)<jupyter_output>No of terms you want15
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377]<jupyter_text>Sum of digits of an integer number<jupyter_code>def sumOfDigits(n):
  sum=0
  assert int (n) == n and n>=0, 'Must be a positive integer'
  while n>0:
    return n%10 +sumOfDigits(int (n/10))
  else:
    return 0
sumOfDigits(546)
#sumOfDigits(-87)<jupyter_output><empty_output><jupyter_text>Power of a number<jupyter_code>def powerOfNumber(x,n):
  assert int (n) ==n and n >=0
  if n==0:
    return 1
  if n==1:
    return x
  else:
    return x*powerOfNumber(x, n-1)
  
powerOfNumber( -2, 5)
def gcd(a, b):
  assert int (a) == a and int (b) ==b, 'Integer numbers only'
  if a%b==0:
    return b
  else:
    return gcd(b, a%b)
print(gcd(48,18))<jupyter_output>6<jupyter_text>Decimal to Binary<jupyter_code>def decToBinary(n):
  assert int (n) ==n
  if n is 0: 
    return 0
  if n is 1:
    return 1
  else:
    return (int (n%2))+10*decToBinary(int (n/2))

decToBinary(13)<jupyter_output><empty_output><jupyter_text>Reverse of a number using Recursion<jupyter_code>def reverseNumber(n, r):
  #assert int (n) == n and n >0
  if n ==0:
    return r
  else:
    return reverseNumber( int ( n/10), r*10+n%10)


reverseNumber(647, 0)<jupyter_output><empty_output><jupyter_text>Largest number in an Array.<jupyter_code>def findMaxNumRec( sampleArray, n): #n is the length of array
  if n==1:
    return sampleArray[0]
  else:
    return max(sampleArray[n-1], findMaxNumRec(sampleArray, n-1))

findMaxNumRec([11, 14, 7, 9, 3, 12], 6)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12216002634178466, 'fraction_numerical': 0.037537043134672377, 'mean_word_length': 4.2926829268292686, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '3084', 'license': 'Apache-2.0', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1177, 'n_words': 344, 'path': 'Recursion_Udemy.ipynb', 'repo_name': 'DebjitHore/Complete-Data-Structures-and-Algorithms-in-Python', 'size': '3037'}