Question: 1 Recursion Warm-up For this problem you are going to rewrite some simple iterative algorithms as recur- sive algorithms. The goal is to build your
1 Recursion Warm-up For this problem you are going to rewrite some simple iterative algorithms as recur- sive algorithms. The goal is to build your understanding of how recursion works and the importance of constructing a proper base case for your algorithm. 1.1 Sum Implement a recursive function that calculates the mathematical sum (-1)'12 +1 which approximates sin(r). You can verify your result by comparing it to the sine function. For sufficiently large n, the above should practically equal the sine function. You will need to come up with a suitable recursive identity and base case for this sum. Use the following function header: function y - sumRecursive(x,n) 1.2 n-choose-k Write a MATLAB function with a header function y nchoosekRecursive(n,k) where y is the number of combinations of k 0 elements that can be generated from a set of n 2 k items. We call this quantity n-choose-k, denoted (k), where rl k n! For this computation, take advantage of the recursive formula (i)-( )-Ci) Take extra care to properly define the base case in your recursion. Be sure to explic itly check that n k, If n
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
