feat: Add Catalan Numbers algorithm implementation to mathematics module#191
Merged
siriak merged 1 commit intoTheAlgorithms:masterfrom Oct 11, 2025
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds a comprehensive implementation of Catalan Numbers algorithms to the mathematics module. Catalan numbers are important in combinatorics and appear in various counting problems in computer science.
- Implements two different calculation approaches: dynamic programming and direct formula
- Provides utility functions for generating sequences and demonstrating applications
- Includes comprehensive documentation and examples for educational purposes
siriak
approved these changes
Oct 11, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces an implementation of Catalan Numbers calculation algorithms to the mathematics module. Catalan numbers are widely used in combinatorics and appear in various counting problems in computer science and mathematics.
What’s Added
• Dynamic Programming Approach (catalan_dp): Efficient O(n) time complexity implementation.
• Direct Formula Approach (catalan_formula): Alternative calculation using the combinatorial formula.
• Utility Functions:
• first_n_catalan(): Generates the first n Catalan numbers.
• catalan_applications(): Demonstrates real-world applications of Catalan numbers.
Key Features
• Performance: O(n) time and space complexity.
• Educational: Includes mathematical explanations and documentation.
• Practical: Multiple approaches provided for flexibility.
• Examples: Sample usage demonstrating various applications.
Applications Covered
• Counting valid parentheses combinations
• Enumerating full binary trees
• Triangulating convex polygons
• Counting monotonic lattice paths
• Arranging non-attacking rooks
File Added
• mathematics/catalan_numbers.r
Testing
The implementation includes several example use cases and has been validated against known Catalan number sequences.
⸻
Type: Feature
Module: Mathematics
Breaking Changes: None