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
2
votes
2 answers

Recursion for Catalan number to Memoized

I have been asked to write a recursive function that will calculate the Catalan number of monotonic lattice paths along the edges of a grid with n × n square cells, which do not pass above the diagonal (pic) I was not allowed to use for-loops, only…
UFC Insider
  • 838
  • 1
  • 7
  • 19
2
votes
5 answers

What is wrong with this Python code about the Catalan numbers?

I'm new to Python. This is a homework problem, but it is tough as I only have a little experience in Java. The code is supposed to print the first Catalan-numbers using its recursive definition: C(n + 1) = C(n) * (4n + 2) / (n + 2) EDIT: My current…
mitlabence
  • 33
  • 9
2
votes
4 answers

Generate All Possible Trees

Given the following data type definition: data FormTree = Empty | Node FormTree FormTree deriving Show I want to write a function which generates an infinite list containing all possible trees sorted after length e.g. the amount of nodes. The…
BullyWiiPlaza
  • 17,329
  • 10
  • 113
  • 185
2
votes
1 answer

Number of binary search trees over n elements

I need to find a number of different binary search trees over n elements. I know, that the number of binary search trees over n distinct elements is Catalan number. But what if numbers can repeat? In Binary Search Tree elements of left subtree are…
Ann Orlova
  • 1,338
  • 15
  • 24
1
vote
1 answer

How to do Catalan Number with recursion in Excel?

I tried to the the following in Excel using N values: http://upload.wikimedia.org/math/b/a/d/bad5db400fcfd7092e2008e376993a27.png I can make the Ci using =COMBIN(2*N;N)/(N+1), but how to make n-i-1 considering my n >= 0 ? Thanks
Martin Gemme
  • 345
  • 3
  • 17
1
vote
2 answers

Does python fail in handling large numbers accurately?

I have made python code to calculate the following expression: With C_n beeing the n:th catalan number defined by C_n = (2nCn) / (n+1) from math import comb import sys from decimal import Decimal def factorial(n): fact = 1 for i in…
1
vote
0 answers

Leetcode 95. Unique Binary Search Trees II - Need help understanding the time complexity

I have a question about understanding the time complexity of the code below. It is the code to generate all unique BST for numbers from 1 to n. I have attached an image of how they describe the time complexity using catalan numbers. It is from…
1
vote
1 answer

Number of ways to form a mountain ranges

I am looking at an application of catalan numbers: Number of ways to form a “mountain ranges” with n upstrokes and n down-strokes that all stay above the original line. Now given a number n, find the number of mountain ranges. public int…
learner
  • 6,062
  • 14
  • 79
  • 139
1
vote
5 answers

What is wrong with my Catalan Number logic?

I wanted to write a code for Catalan Numbers.Catalan Numbers are defined as follows: C(n) = 2n C n/(n+1). But instead of computing (2n C n) I wanted to calculate the catalan numbers bottom up using the following facts: Catalan(n) = 2n! /n! * n!…
station
  • 6,715
  • 14
  • 55
  • 89
1
vote
2 answers

for Binary tree, suppose there is n node, how many different structure can I construct?

Consider a binary tree with n nodes. How many different possible binary trees structures are there? I tried something like: n number of different structure: 1 1 2 4 3 16 so is that 4(n-1) for n >1 ; 1 for n == 1?
Don Lun
  • 2,717
  • 6
  • 29
  • 35
1
vote
1 answer

C programming numbers and mountains

I created a C program that gives the nth catalan number.Everything is working so far. Here it is: #include int catalan(int); main() { int number, catalannumber; printf("This is a program to find a given catalan…
Merlin
  • 97
  • 7
1
vote
2 answers

Error while calculating Catalan number sequence

Whatever I tried this following code throws ArithmeticException with message "Non-terminating decimal expansion; no exact representable decimal result." on bigger numbers (like 43, 50, 56 etc). Here is the code: private BigDecimal catalan(int n) { …
brack11
  • 171
  • 3
  • 11
1
vote
2 answers

Long numbers. Division

world! I have a problem. Today I tried to create a code, which finds Catalan number. But in my program can be long numbers. I found numerator and denominator. But i can't div long numbers! Also, only standard libraries was must use in this program.…
user577395
  • 125
  • 1
  • 6
1
vote
1 answer

Recurrence Relation: Writing a recurrence relation

I'm trying to write a recurrence relation for this algorithm.But I've got confused with the "root" variable.Can anyone help me or suggest me a better recursive algorithm to count the number of possible binary trees with n nodes? Algorithm…
Saman Nourkhalaj
  • 61
  • 1
  • 1
  • 10
1
vote
1 answer

Generating sequence of numbers with recursion python

The goal is to generate catalan numbers ! my code works up to n = 30 (i tried the same algorithm in JAVA and it's totally correct,but, then something strange happens with python , it gives wrong numbers back after n=30. I'm totally sure that there…
user4411105