plz answer is guys
I will mark u as a brainlest
(python programming language)
Answers
Answer:
1. Disadvantages of Python Recursion
1.Slow.
2.Logical but difficult to trace and debug.
3.Requires extra storage space. For every recursive calls separate memory is allocated for the variables.
4.Recursive functions often throw a Stack Overflow Exception when processing or operations are too large.
2.
def binarySearch (arr, l, r, x):
# Check base case
if r >= l:
mid = l + (r - l)//2
# If element is present at the middle itself
if arr[mid] == x:
return mid
# If element is smaller than mid, then it can only
# be present in left subarray
elif arr[mid] > x:
return binarySearch(arr, l, mid-1, x)
# Else the element can only be present in right subarray
else:
return binarySearch(arr, mid+1, r, x)
else:
# Element is not present in the array
return -1
3. Img uploaded
4. Stack
5.
# Function to print first n
# Fibonacci Numbers
def printFibonacciNumbers(n):
f1 = 0
f2 = 1
if (n < 1):
return
for x in range(0, n):
print(f2, end = " ")
next = f1 + f2
f1 = f2
f2 = next
# Driven code
printFibonacciNumbers(7)
6.
# Function to calculate x raised to the power y
def power(x, y):
if y==0:
return 1
if y%2==0:
return power(x, y/2)*power(x, y/2)
return x*power(x, y/2)*power(x, y/2)
# Function to calculate order of the number
def order(x):
# variable to store of the number
n = 0
while (x!=0):
n = n+1
x = x/10
return n
# Function to check whether the given number is
# Armstrong number or not
def isArmstrong (x):
n = order(x)
temp = x
sum1 = 0
while (temp!=0):
r = temp%10
sum1 = sum1 + power(r, n)
temp = temp/10
# If condition satisfies
return (sum1 == x)
# Driver Program
x = 153
print(isArmstrong(x))
x = 1253
print(isArmstrong(x))
Explanation: