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

Calculating a catalan number in C

I'm struggling with some code I have to write for an assignment in C. I have to calculate a Catalan number recursively. The following formula is given: Formula IMG. The awnsers should be: 0 > 1 (Filling in 0 should print 1) 5 > 42 (Filling in 5…
Laurens
  • 33
  • 8
0
votes
1 answer

How to optimize programm to calculate catalan numbers

I have to write a programm that calculates the catalan numbers and therefor I hava to calculate some factorials. The Problem is that the programm needs to be able to process inputs of up to 5000 and also has certain time limits that have to be…
Tobias
  • 41
  • 2
  • 8
0
votes
1 answer

Python: Iterate through balanced parentheses on an expression

I found some code to iterate through arithmetic operators across a static, excecutable formula in Python: from itertools import product import numpy as np operands = np.array(['a', 'b', 'c', 'd', 'e']) operators = np.array([ '&', '|']) for opers…
Craig Nathan
  • 197
  • 10
0
votes
3 answers

How to find number of correctly matched parentheses using Catalan numbers?

I have a task to find number of expressions containing n parentheses which are correctly matched. So, I decided to use Catalan number. Here is a python code. from decimal import Decimal n = int(input()) res = Decimal(1) k = n//2 for i in…
0
votes
1 answer

No of BST possible with n unlabelled nodes

I was recently asked to tell the no of BST possible with n unlabelled nodes in an interview. But I couldn't understand the point of unlabelled nodes in BST and was not able to answer properly. What should be the appropriate answer to this question?
Vanshika
  • 49
  • 1
  • 6
0
votes
2 answers

number of valid parenthesis using dynamic programming [Uber phone interview]

For given n find the number of valid combinations of valid parenthesis.I told him direct formula of Catalan number(becuase i encountered this prob earlier) but he specifically wanted this problem Solution using dynamic programming and wanted working…
user10891599
  • 41
  • 1
  • 5
0
votes
2 answers

Convert Catalan recursive algorithm to iterative

Hello all mighty hackers, mathematicians and coders! I work hard to create a recursive algorithm for the Catalan numbers equation below C(n) =∑ C(i−1) C(n−i) (and simplification of this equation using stirling numbers or other forms is not an…
0
votes
1 answer

Method that checks if the method was already executed with that input

public class CatalanNumbers { private int howManyVariaties; private int catalanNumber; private int catalanNumber; public int catalan(int a) { if (Method was never executed with that input) { …
0
votes
1 answer

Catalan number calculation using Python?

I am writing a Python code to generate Catalan numbers using the mathematical formula given here: C(0) = 1 and C(n) = (2(2n − 1) / (n + 1)) * C(n − 1) per this website here. (https://rosettacode.org/wiki/Catalan_numbers) However, when I am writing…
R_Moose
  • 103
  • 9
0
votes
1 answer

How does the catalan() function works here?

I stumbled across this function to calculate the catalan number: def catalan(n): if n == 0: return 1 else: sum = 0 for i in range (n): sum +=(catalan(i))*(catalan(n-1-i)) return sum My question is how…
0
votes
0 answers

Is there a way possible in python to find the number of node which are connected to two Leaf in a full binary tree

I am not a computer programmer but I need this idea for one of my projects. I would explain what I am trying to achieve: These are two pictures picture picture. Can we write a code to find the number of nodes whose both children are the terminal…
RAAS
  • 1
  • 1
0
votes
5 answers

Recursive method for Catalan numbers in R

I am trying to write a function in R that would take an input numb and output the corresponding Catalan number. For your information, the recursive formula for Catalan Numbers is, C_0 = 1; C_n = {(4n - 2)*C_(n-1)}/(n+1) My code is as follows,…
Pragyaditya Das
  • 1,648
  • 6
  • 25
  • 44
0
votes
1 answer

How do you compute the run time for the naive solution for Matrix Chain Multiplication?

I'm working on Matrix Chain Multiplication. And the naive solution is equivalent to the Catalan number of the problem. This is what it says in the solution. That the naive solution ends up working out to be O(2^n) by reducing the parenthesizing…
user6679212
0
votes
1 answer

How to determine the amount of binary search trees recursively?

What is a possibility for determining the amount of different binary search trees on a key set of 1,...,n?
Tesla
  • 141
  • 8
0
votes
1 answer

Java - Catalan numbers IllegalArgumentException and boolean to int problems

I am trying to write a program that takes an integer value (n) from the user, checks that it is greater than 0 and less than 30. If this is the case it calls my catalan numbers method and substitutes n in. If the inputted number is less than 0 or…
Shaun
  • 97
  • 9