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
3
votes
1 answer

Number of valid parenthesis catalan number explanation

While studying about catalan numbers, some of the applications that I came across were: no of possible binary search trees using n nodes. no of ways to draw non-intersecting chords using 2*n points on a circle. no of ways to arrange n pairs of…
Yash
  • 5,225
  • 4
  • 32
  • 65
3
votes
1 answer

Increasing performance when doing calculations with huge numbers (BigInteger)

I am a less experienced coder doing an exercise where I need to calculate the product of two catalan sequences for every single n-value between 0 and 5000 and then summarize those products. The code currently outputs the correct answer but takes…
MelsunMandela
  • 33
  • 1
  • 4
3
votes
2 answers

Maths: Find permutation number using one stack

It's more a math problem I guess, nothing programming. Suppose I have a stack and I want to find the permutations of numbers 1,2,3,...n. I can push and pop. e.g. if n=2: push,pop,push,pop 1,2 and push,push,pop,pop 2,1 if n=4 I can only get 14 from…
alhid
  • 61
  • 2
3
votes
2 answers

Calculating Catalan Number

I am using this code to calculate the Catalan Number. It gives me right value until n=6 , then it gives me wrong values. I checked manually using a calculator. For Ex: when n=5 Catalan Number is 42 which is right but when n=7 , it gives me 6 which…
haby
  • 33
  • 4
3
votes
3 answers

Permutation At A Railway Track(Stack Implementation)

Engines numbered 1, 2, ..., n are on the line at the left, and it is desired to rearrange(permute) the engines as they leave on the right-hand track. An engine that is on the spur track can be left there or sent on its way down the right track, but…
user4371190
3
votes
2 answers

What is the space complexity of this algorithm?

This is problem 9.6 from Cracking the Coding Interview (5th edition) Implement an algorithm to print all valid combinations of n-pairs of parenthesis EXAMPLE Input: 3 Output:"((())), (()()), (())(), ()(()), ()()()" Here is the algorithm I…
3
votes
1 answer

Balanced Parentheses

I was wondering if anyone can answer me which is number of results generated in the backtracking solution for the next problem: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example,…
user2773755
  • 117
  • 2
  • 9
3
votes
2 answers

Determine structural equivalence of BSTs with standard traversal

Is it possible to decide the structural equivalence of two binary search trees just with the results of traversals, pre order, in order and post order. Assume I have only the result arrays of all the traversals. I know in order traversal alone,…
Karthikeyan
  • 990
  • 5
  • 12
3
votes
1 answer

How many binary trees are there, if the leafs's order from left to right is fixed?

Let's represent the tree via list. If the number of the leafs is two, A and B. Then there is only one tree (A B). If the number of the leafs is three, A, B and C. Then there are two trees ((A B) C) and (A (B C)). So if there are N leafs, how many…
louxiu
  • 2,830
  • 3
  • 28
  • 42
3
votes
3 answers

How to find number of possible binary tree topological permutations?

Given number of binary tree nodes (X) write method that returns the number of random permutations of binary trees with X nodes. Examples: X=1: 1 o X=2: 2 o o o o X=3: 5 o o o o o o …
aviad
  • 8,229
  • 9
  • 50
  • 98
2
votes
3 answers

Writing recursive algorithm with dynamic programming

I want to write an algorithm using a dynamic programming technique, which does the following: Find number of monotonic paths along the edges of a grid with n × n square cells, which do not pass above the diagonal. A monotonic path is one which…
max12345
  • 29
  • 2
  • 9
2
votes
0 answers

recursive implementation of nested for-loops (variable branching factors) to generate Catalans numbers

I am given the number of trees of size N with branching factor b and attempting to generate Catalans number without the use of a separate recursive function to generate the the number of nested for loops. Ive tried this so far int catalan(int size,…
jack1950
  • 21
  • 1
2
votes
1 answer

Java - looping issues for catalan number program

I am trying to write a program that takes an integer value (n) from the user then invokes my catalan numbers method and finds the nth value. It all works aside from two errors; firstly when I type in 'quit' it gives the error message 'Exception in…
Shaun
  • 97
  • 9
2
votes
5 answers

Recurrence Approach : How can we generate all possibilities on braces?

How can we generate all possibilities on braces ? N value has given to us and we have to generate all possibilities. Examples: 1) if N == 1, then only one possibility () . 2) if N==2, then possibilities are (()), ()() 3) if N==3, then…
siva
  • 1,693
  • 2
  • 21
  • 29
2
votes
2 answers

Number of valid parenthesis

I have to find out the number of valid parenthesis.Parenthesis are of two type [] ,(). How many ways are there to construct a valid sequence using X and Y number of [] ,(). For this problem we consider ([]) is invalid way i.e () can't hold []. Is…
user6250837
  • 458
  • 2
  • 21