Question: The algorithms below are mutually recursive; that is, each one calls the other, until one of them reaches a base case. Answer the following questions

The algorithms below are mutually recursive; that is, each one calls the other, until one of them reaches a base case. Answer the following questions for how we analyze these algorithms. Input: n: non-negative integer Output: ??? 1 Algorithm: Mystery1 2 if n = 0 then 3 return 4 end 5 Output "left" 6 Mystery2 (n - 1) 7 Output "forward" 8 Output "right" 9 Mystery1 (n - 1) 10 Output "forward" 11 Mystery2 (n - 1) 12 Output "right" 13 Output "forward" 14 Mystery2 (n - 1) 15 Output "left" 16 return Input: n: non-negative integer Output: ??? 1 Algorithm: Mystery2 2 if n = 0 then 3 return 4 end 5 Output "right" 6 Mystery1 (n - 1) 7 Output "forward" 8 Output "left" 9 Mystery2 (n - 1) 10 Output "forward" 11 Mystery2 (n - 1) 12 Output "left" 13 Output "forward" 14 Mystery1 (n - 1) 15 Output "right" 16 return 1. Let S(n) represent the amount of time required to compute Mystery1 on an input of n and T(n) the amount of time required to compute Mystery2 on an input of n. Give recurrences for S(n) and T(n). 2. Draw a recurrence tree that represents all of the recursive calls made by Mystery1 (S(n)). In addition to labelling each node with the size of the input, you will also need to label each node with which algorithm is being called (S vs. T). 3. Analyze this recurrence tree to find the worst-case time complexity for Mystery1 (S(n)). You may use the fact that sigma^n _i = 0 c^i = theta (c^n) for any constant c > 1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
