JAVA LAB PROGRAMMING Write a Java program to find nth Catlan number. Try to give the highly Optimised Code and code should take input from the user.
Max Function
Statistical function is of many categories. One of them is a MAX function. The MAX function returns the largest value from the list of arguments passed to it. MAX function always ignores the empty cells when performing the calculation.
Power Function
A power function is a type of single-term function. Its definition states that it is a variable containing a base value raised to a constant value acting as an exponent. This variable may also have a coefficient. For instance, the area of a circle can be given as:
Required:
JAVA LAB PROGRAMMING
Write a Java program to find the nth Catalan number.
Try to give the highly Optimised Code and the code should take input from the user.
Approach:
Take the number from the user using the scanner class object and for the Catalan number we know that:
C0 = 1;
C1 = 1
C2 = C0 C1 + C1 C0 = 2
We get the recursion formula and by using the two nested loops, we can the nth Catalan number and print the result on the console.
For solving the same problem, again and again, we can tabulate the previous result and fill it into the table, that technique is also known as Dynamic Programming.
Time Complexity: O(n2)
Space Complexity: O(n)
for further help, please see the code below with the output.
Step by step
Solved in 4 steps with 3 images