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
1
vote
2 answers

Need to generate possible trees from list

I want to generate all possible trees from an int list [Int] -> [T] but I generate only one tree. 1 1 2 2 3 5 4 14 5 42 like these Catalan numbers. If my list size is 3, I want to generate 5 possible…
samcuk
  • 21
  • 4
1
vote
1 answer

Python does not follow order of PEMDAS?

I am programming a catalan number generator for homework, and I am doing a recursive program in pytohon. The program: def catalan(n): if n == 0: c_f = 1 else: c_f = ((4*n-2)/(n+1))*catalan(n-1) return c_f print…
Brenda So
  • 191
  • 1
  • 8
1
vote
1 answer

How to list all binary trees ordered by the catalan relation

I am looking for an algorithm in Lisp or in pseudo-code to list all binary trees ordered by the catalan relation. For instance I want with the input '(a b c d) get this result: (a (b (c d))) (a ((b c) d)) ((a b) (c d)) ((a (b c)) d) (((a b) c)…
yannics
  • 179
  • 10
1
vote
5 answers

Calculating the complexity of algorithm to print all valid (i.e., properly opened and closed) combinations of n-pairs of parentheses

I would like your opinion on the time and space complexity of this algorithm I implemented (in Python) to calculate the complexity of algorithm to print all valid (i.e., properly opened and closed) combinations of n-pairs of parentheses (see all…
agave1987
  • 33
  • 3
1
vote
2 answers

Dividing two Ulong integers outputs wrong result

I am writing a program for Catalan number. So here is the formula for that: I decided to use the middle part of the formula, because the other parts are too abstract for my knowledge (maybe I slept too much in math classes). Actually my program…
Kadiyski
  • 115
  • 6
1
vote
2 answers

Labelled vs Unlabelled Binary tree?

This Wolfram link talked a bit about 'Labelled' Binary tree. So is there something called 'Unlabelled' binary tree as well ? A concise explanation of Both would be really nice. Why am i searching for this ? I'm trying to answer this question : We…
Somjit
  • 2,503
  • 5
  • 33
  • 60
1
vote
1 answer

Strange bug with Catalan number generator

I'm trying to write a iterative catalan number generator as opposed to a recursive one. It works, but only up until the number "10", and then it starts to print out numbers that don't make sense. Here's what I have so far. public static long…
vdub
  • 41
  • 4
1
vote
1 answer

Is there link between the number of possible binary trees as a function of the tree's height?

Dealing with balanced and unbalanced binary trees. height = 0, possible trees = 1 (nothing) height = 1, possible trees = 1 (leaf) height = 2, possible trees = 3 I'm looking at the Catalan function but it has not lead me anywhere beneficial, mostly…
User
  • 23,729
  • 38
  • 124
  • 207
1
vote
2 answers

Calculate the nth Catalan number

I wrote some code to calculate the Nth catalan number. However, it isn't returning the correct result when N=20 and onwards. The results when N<20 is correct though, so I'm not sure what is wrong. So, when N=20, its supposed to return 6564120420,…
user2211574
  • 39
  • 1
  • 7
1
vote
1 answer

Catalan Number in using Dynamic Prog

I was calculating the number of Binary Search Trees with n nodes, and I found out that it is Catalan Number. Now, using DP, here's my attempt. create arr[n+1]; arr[0]=1; arr[1]=1; for(i=2;i
Kraken
  • 23,393
  • 37
  • 102
  • 162
1
vote
4 answers

generate all structurally distinct full binary trees with n leaves

This is a homework, I have difficulties in thinking of it. Please give me some ideas on recursions and DP solutions. Thanks a lot generate and print all structurally distinct full binary trees with n leaves in dotted parentheses form, "full" means…
lxx22
  • 225
  • 7
  • 17
0
votes
3 answers

What is the complexity of the next grammar

I'm developing a Generalized Parsing Algorithm and I'm testing it with next rule S ::= a | SS Well, the algorithm is showing me all trees generated for the string composed of n a's. For example next table shows the time used by the algorithm due to…
yuryeuceda
  • 11
  • 2
0
votes
2 answers

Catalan numbers in MIPS assembly

Catalan numbers are recursively defined by the following equation. This is the test case: Program input: 0 1 2 3 6 9 Expected output: 1 1 2 5 132 4862 Obtained output: 1 1 2 4 32 256 So my output is wrong when n = 3, the output should be 5…
0
votes
2 answers

Java "Catalan number" generator is almost working right

What a Catalan number is: https://en.wikipedia.org/wiki/Catalan_number I am doing some Java exercises and a couple of the test numbers aren't passing even though I am certain they should be. Successfully I got 11 of the 13 results but when it comes…
Kemper Lee
  • 276
  • 4
  • 10
0
votes
1 answer

How many binary trees possible with N nodes using Catalan Number concept

So I was understanding Catalan Number Concept and try to implement it in code using topDown DP approach, so the recurrence relation is from what I have learned, f(N) signifies total count of binary search trees possible by N number of nodes f(N) =…
codosopher
  • 119
  • 12