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

Printing mountain ranges algorithm

/\ / \ / \ /\/\ / \ /\ /\/ \ /\ / \/\ /\/\/\ for n=3 pairs of ups and downs I have 5 possible way to draw these mountains.(I should never go below the x=0 axis). I have the following long javascript code which works fine…
ayt_cem
  • 105
  • 1
  • 9
0
votes
5 answers

calculate catalan numbers up to a billion

I'm new to python (and programming in general), I was asked in my class to calculate Catalan numbers up to a billion but the program I wrote for it is not working as intended. from numpy import division C=1 n=0 while…
Luis F Llano
  • 41
  • 11
0
votes
1 answer

Calculating matrix chain mutlipication with Catalan numbers

I studied Matrix Chain Multiplication problem and I understand what the algorithm does. Lately, I came across Catalan numbers, which came in handy when solving the parenthesization problem. The problem appeared to me very similar to Matrix Chain…
Aza T
  • 589
  • 4
  • 11
0
votes
1 answer

Calculating large catalan numbers modulo a prime

Does anybody know a fast algorithm for calculating a large catalan number modulo a prime (which is 1.000.000.007) with an input value of about 500.000 Already spent quite some time on it but I wasn't able to modify the normal formular to work with…
0
votes
1 answer

Calculating catalan numbers with memoization

I am trying 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, mem = None): if n==0: return 1 if mem==None: mem={} sum=0 if n not…
user5625976
0
votes
1 answer

Recursion with versus without memoization

I got homework in school to calculate Catalan number with recursion: 1st without memoization def catalan_rec(n): res = 0 if n == 0: return 1 else: for i in range (n): res += (catalan_rec(i))*(catalan_rec(n-1-i)) return res 2nd…
Beginner
  • 57
  • 1
  • 1
  • 8
0
votes
0 answers

Number of Binary trees

What is the number of different binary trees and Binary search trees that can be formed from n nodes? Pls Note : 1) I am asking for Binary trees and not full Binary trees (in which case the answer is Catalan(n))? 2) In case of BST's again pls…
0
votes
1 answer

Determining time complexity of recursive function

I have written a recursive function which computes Catalan Numbers. The recursion formula is . My code: def catalan(n): # We call this function. To my opinion it is more elegant. d = dict() return catalan_rec(n,d) def catalan_rec(n,d): …
Galc127
  • 175
  • 6
0
votes
3 answers

Finding Balanced Parenthesis Involving Math

I've tried to solve this question for the past couple of hours and I just don't understand it. I know there must be a sort of mathematical calculation to calculate this but I don't know how to exactly calculate it. I know this code does not make…
geforce
  • 79
  • 1
  • 1
  • 12
0
votes
3 answers

About catalan number's expression from wiki

According to the wiki catalan definition from wiki, I see the expression below: I can understand the first two expressions, but really confused about the third one. The pi symbol stands for the multiply. Does the expression mean the code below: for…
Vizi
  • 25
  • 1
  • 7
0
votes
1 answer

Catalan numbers in functional languages

The Catalan numbers satisfy the recurrence Of course Catalan numbers have a closed form expression involving binomial coefficients. Also we can express C_n in terms of C_{n-1} alone. What I am wondering is how one can implement this kind of…
Kuai
  • 135
  • 7
0
votes
2 answers

Calculate time complexity of nontrivial problems

I am having trouble in calculating the time complexity of program shown below. It is a simple program to generate valid parentheses such as "((()))" "(()())" etc. However, I don't really know how to estimate time complexity for this kind of…
Lamian
  • 313
  • 2
  • 5
  • 12
0
votes
4 answers

What are the total number of possible ordered trees with N nodes?

For example for N=3, we can find easily by listing them all, but when asked for any arbitrary N value I am facing problem.
abhilash_goyal
  • 711
  • 1
  • 10
  • 31
0
votes
1 answer

My code Catalan number in C is not working ( using recurrence formula )

I am trying to insert all Catalan number in array, but my code is not working. Description: Insert the elements in the Catalan sequence in the array given initialized only for C[0]. Inputs: address of array n: next position to be filled; top:…
nader
  • 1
  • 1
0
votes
2 answers

all possible numerical expressions

one totally useless question: I bought a numerical game, it's made of two black dice plus 5 coloured ones. the two black ones form a 2 digits number, ranging from 11 to 66, the other 5 are the numbers you can use, combining them in all possible…
mariotomo
  • 9,438
  • 8
  • 47
  • 66