Question: I would like to know : 1) time complexity 2) space complexity for the following functions- (python) A) def rev_num(num): the function gets a

I would like to know :

1) time complexity

2) space complexity

for the following functions- (python)

A)

def rev_num(num): """ the function gets a number and returns reversed number using recursion """ if num < 10: return num else: n = int(math.log10(num)) #how many digits there is in the number without the unit digit return ((num % 10) * 10**n) + rev_num(num//10)

B)

def mod_of_3(num): """ The function gets an integer number and checks if every three following digits the remnant of division of 3 is different or not (returns True if yes, else False) using recursion """ if num < 10: return True if ((int(math.log10(num)) + 1) == 2): #if the number has two digits if((num % 10) % 3) != ((num // 10) % 3): return True return False if ((int(math.log10(num)) + 1) == 3): #if the number has three digits digits mod_units = num % 10 % 3 #remnant of division of unit digit by 3 mod_tens = num //10 % 10 % 3 #remnant of division of tens digit by 3 mod_hundreds = num // 100 % 10 % 3 #remnant of division of hundreds digit by 3 if (mod_units == mod_tens or mod_tens == mod_hundreds or mod_units == mod_hundreds): return False return True and mod_of_3(num//10)

C)

def is_up(num): """ the function gets a number and checks if its digits form an ascending sequence using recursion """ if num < 10: return True if (num % 10 <= num //10 % 10): return False return True and (is_up(num//10))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!