Questions tagged [catalan]

Catalan numbers are mainly used in computer science with enumerating full binary trees or solving combinatorial problems. Do not use this tag with the spoken language Catalan or the geographic region known as Catalonia or Fuss-Catalan numbers.

References

Related sites

Related sequences

Catalan numbers are for full binary trees, e.g. all nodes have 0 or 2 branches, and count only leaves, while Motzkin numbers are for regular binary trees, e.g. all nodes have 0,1, or 2 branches, and count all nodes.

Notes

For Fuss-Catalan numbers use tag fuss-catalan-numbers

114 questions
0
votes
1 answer

Code in Prolog generate all structurally distinct full binary trees with n node

generate all structurally distinct full binary trees with n leaves in Prolog. The problem is given the number of leaves, output all distinct full binary trees. 'Full' here means any internal node must have two children, left and right.
lxx22
  • 225
  • 7
  • 17
-1
votes
2 answers

Determining the running time of the following code (recursion with a loop inside)

I have the following code and need to determine the running time of this algorithm. int res=0; if (n <= 1) return 1; for (int i = 0; i < n; i++) res += Catalan(i) * (Catalan(n - i - 1); return res; I am having a hard time to determine…
-1
votes
2 answers

Basic Catalan numbers

I wanna write a program that prints out all Catalan numbers less than or equal to say 100000. Such are given by cn=1 and cn1 = ((4n+2)/n+2)*cn (next value). When I try it I get the below error. My code is : cn,cn1 = 1,2 n = 1 while…
ak19
  • 9
  • 4
-1
votes
1 answer

nth Catalan number using Combinations

I have written a c++ program to find n-th catalan number by using combinations but I am always getting output 0. Please point out mistakes in this code: #include using namespace std; int fact(unsigned int x) { unsigned…
umar
  • 551
  • 1
  • 6
  • 13
-1
votes
2 answers

calculating catalan numbers using memoization

I am tring to use memoization in order to calculate catalan numbers, but it just does not seem to work, what do I need to change? def catalan_mem(n, memo = None): if n==0: return 1 if memo == None: memo = {} b=0 if n…
shaked
  • 87
  • 1
  • 4
-1
votes
2 answers

Creating Catalan number loop and graphing it [python]

Let me preface it with that I am new to python completely and programming for that matter and I need to create a program to print all Catalan numbers up to one trillion. I have the basics of the program written out but I can't seem to understand why…
-2
votes
1 answer

It is possible to make a catalan number in C with tail recursion?

I have the job of verifying and if it is possible to calculate the catalan number by means of the tail recursion, I could do the calculation with the stack recursion using the definition, but I could not do it by means of the tail recursion int…
-3
votes
1 answer

Compute the number of binary trees with i nodes

Let bi be the number of binary trees with i nodes. Compute b10. This is a problem I've come upon. I've able to come up with these so far: B0=1 B1=1 B2=2 B3=5 B4=12 It quickly gets a bit too much as I gets bigger. Can anyone think of a better…
spider
  • 53
  • 5
-3
votes
1 answer

How to list all the possible binary search trees with n nodes?

I want to list all the possible binary search trees. I know that the number will be the catalan number. But i want to list them also. Let's say that I assign letters to each position of a binary search tree as shown below Then want to list all…
1 2 3 4 5 6 7
8