MIPS Language 2. Complete catalan_recur function, which recursively calculates the N-th Catalan number from a given posi
Posted: Sun May 15, 2022 12:51 pm
MIPS Language
2. Complete catalan_recur function, which
recursively calculates the N-th Catalan number
from a given positive integer input n. Catalan number sequence
occurs in various counting problems. The sequence can be
recursively defined by the following equation.
And this is the high-level description of the recursive
Catalan.
>> a0: the argument for the given positive integer input,
n
Example:
Program input:
0 1 2 3 6 9
Expected output:
1 1 2 5 132 4862
def catalan_recur(n): if n <= 1: return 1; else: res = 0 fori in range(n): # i = 0 - (n-1) res += catalan_recur(i) * catalan_recur(n-i-1) return res;
2. Complete catalan_recur function, which
recursively calculates the N-th Catalan number
from a given positive integer input n. Catalan number sequence
occurs in various counting problems. The sequence can be
recursively defined by the following equation.
And this is the high-level description of the recursive
Catalan.
>> a0: the argument for the given positive integer input,
n
Example:
Program input:
0 1 2 3 6 9
Expected output:
1 1 2 5 132 4862
def catalan_recur(n): if n <= 1: return 1; else: res = 0 fori in range(n): # i = 0 - (n-1) res += catalan_recur(i) * catalan_recur(n-i-1) return res;