FUNCTION
Catalan_Triangle_Row
Computes the row of the given order in Catalan's triangle.
You're viewing an older version of this page (#5349). View the current version.
Interface
#include <codecogs/maths/combinatorics/sequences/catalan_triangle_row.h>
using namespace Maths::Combinatorics::Sequences;
The recurrent formula used to generate Catalan's triangle is
$$C(0, 0) = 1 \qquad C(i, 0) = 1 \qquad C(i, j) = 0, \quad \forall i < j$$
(1)
$$C(i, j) = C(i, j - 1) + C(i - 1, j)$$
(2)
The number found at $C(i, i)$ represents the Catalan number of order $i$.
Parameters
n
the order of the row requested
first
internal flag selecting which code path builds the row; leave this at its default value of true when calling this function directly
Returns
the row of order n in Catalan's triangle, as a standard C++ vector
Example:
#include <codecogs/maths/combinatorics/sequences/catalan_triangle_row.h>
#include <iostream>
int main() {
std::vector<int> row = Maths::Combinatorics::Sequences::catalan_triangle_row(6);
std::cout << "Length of row: " << row.size() << std::endl;
for (int i = 0; i < row.size(); i++)
std::cout << row[i] << " ";
std::cout << std::endl;
return 0;
}
Output:
Length of row: 7
1 6 20 48 90 132 132
References
SUBSET, a combinatorial functions library created in C++, http://www.csit.fsu.edu/~burkardt/cpp_src/subset/subset.html
This function's source code is only visible to registered users — documentation and the calculator above are free to use either way. Sign in to see it.