Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
- 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.
// Project 4 pi_approximation (int m) public static double pi_approximation(int n) return ; // Project 4 longestSubsequence (String s) public static int lengthof LongestSubsequence(String a, String b) return
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