The nth Catalan number can be found using recursion or dynamic programming. Here's one way to find it using recursion:
main.php238 chars14 lines
This implementation has a time complexity of O(4^n).
To reduce the time complexity, we can use dynamic programming with memoization. Here's an implementation using memoization:
main.php357 chars19 lines
This implementation has a time complexity of O(n^2) and a space complexity of O(n).
gistlibby LogSnag