Question
For each of the methods you need to write you are given enough information in the project to implement the function. If you have questions,
For each of the methods you need to write you are given enough information in the project to implement the function. If you have questions, do not hesitate to ask! You receive no credit for solutions which do not use recursion. For each of these questions you should implement the algorithm specified. Failure to use the specified algorithm will result in no credit for that question.
- If you have not already done so, download the source code from https://github.com/CGCC-CS/205activity4.git (Links to an external site.). You should include the solutions for both the activity and the project in your submission.
- Add the following methods to the Recursion class from the source code. Each method should be implemented recursively even if a closed-form or iterative solution also exists. (10 points each)
- Write a recursive method balance(n) that finds the floor of the meanof x & y as follows; If the two parameters are within 1 of each other, return the smaller number Otherwise, subtract one from the larger parameter and add one to the smaller parameter and balance the result.
- Write a recursive method called Ackermann(x, y) that computes the Ackermann function defined as follows: The Ackermann function grows very quickly, so you may run into a stack overflow with m>3. You can see a table of correct values here: https://en.wikipedia.org/wiki/Ackermann_function (Links to an external site.)
- Write a recursive method called pi_approximation(n) that calculates the Leibniz approximation of given below. Note that you will need to multiply the result by 4 to get the approximation of . Note that the nth term can be calculated as
- Write a recursive method called lengthOfLongestSubsequence(a, b) that calculates the length of the longest common subsequence (lcs) of two strings. For example, given the two strings aaacommonbbb and xxxcommonzzz the lcs is common which is 6 characters long so your function would return 6. The length of the lcs of two strings a & b can be calculated as follows: 0 if the length of a or b is 0 1 + lcs(a[1-], b[1-]) if a[0]=b[0] max(lcs(a,b[1-]), lcs(a[1-],b)) in all other cases where a[1-] is the string with the first character removed. You only need to return the length of the longest common subsequence. You do not need to find the longest common sequence.
You will need to submit your program files and a pdf that answers the following:
Briefly describe any issues (if any) you ran into with this project:
Copy your output:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started