Consider the following function: 1. def mystery(n: int, m: i…

Consider the following function: 1. def mystery(n: int, m: int) -> int :2.     if n == 0 :       # special case 13.         return 04.     if n == 1 :       # special case 25.         return m6.     return m + mystery(n – 1), m) What will happen if lines #2 and #3 were swapped with lines #4 and #5?

Consider the following code snippet for recursive addition:…

Consider the following code snippet for recursive addition: def add(i: int, j: int) -> int :    # assumes i >= 0    if i == 0 :        return j    else :        return add(i – 1, j + 1) Identify the base-case / stopping-case in this recursive function.

This function is supposed to recursively compute x to the po…

This function is supposed to recursively compute x to the power n, where x and n are both non-negative: 1. def power(x: int, n: int) -> int:2.     if n == 0 :3.         ________________________________4.     else :5.         return x * power(x, n – 1) What code should be placed in the blank to accomplish this goal?

The following code segment is supposed to determine whether…

The following code segment is supposed to determine whether or not a string is a palindrome, meaning that it is the same forward and backward. def isPalindrome(s: str) -> bool :    return palindromeHelper(s, 0, len(s) – 1) def palidromeHelper(s: str, l: int, h: int) -> bool :    if h

Consider the following code segment: def triangle_area (side…

Consider the following code segment: def triangle_area (sideLength: int) -> int:    if sideLength == 1:        return 1    return triangle_area(sideLength – 1) + sideLength print(triangle_area(5)) How many times is the triangle_area function called when this code segment executes?

Consider the code for the recursive function my_print shown…

Consider the code for the recursive function my_print shown in this code snippet: 1. def my_print(n: int) -> int:2.     if n == 0 :3.          return 04.     else :5.         return n + my_print(n – 1) To avoid infinite recursion, which of the following lines of code should replace the current terminating case?