Question: The atoi() function takes a string (which represents an integer) as an argument and returns its value. Consider the following two recursive implementations atoiR1 ()



The atoi() function takes a string (which represents an integer) as an argument and returns its value. Consider the following two recursive implementations atoiR1 () and atoiR2 (). def atoiR1(string, num): if ( Len (string)== ) return if len(string)==1 : return int(string) +(num10) num =int( string [0:1])+( num 10) return atoiR1 (string [1:], num) def atoiR2(string): if ( len ( string )==0) : return 0 if len( string )==1 : return int(string) return atoiR 2(string[0:1])10+int(string[1]) When comparing atoiR1 and atoiR2: If implemente din Python as indicated above both atoiR1 and atoiR2 has the same Big-O space complexity If implemented in Python as indicated above atoiR1 has a lower Big-O space complexity atoiR2 If implemente din C both atoiR1 and atoiR2 has the same Big-O space complexity If implemente d in Python as indicated above atoiR1 has a higher Big-O space complexity atoiR2 Consider a recursive function sumDigit sR (num) that returns the sum of the digits of the input parameter, which is an integer called num. It can be assumed that 'num' is a non-negative For example: sumDigitsR (1983)=21. If sumDigitsR was re-written into an iterative version, what would be the space complexity of the iterative algorithm? O(n2) O(n) O(1) O(logn) None of the other answers are correct Consider the function below to reverse the substring of S from position i to j. If S were defined as a string "abcdefg" then reversestring (S,0,len(S)1) function would return "gfedcba" reversestring (5,3,4) function would return "abcedfg" Function: What is the time complexity of revergestring? O(1) O(n2) O(logn) O(n) None of the other anwers are correct
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
