-
Notifications
You must be signed in to change notification settings - Fork 20.9k
Optimize Factorial Algorithm (Iterative Implementation) and Add Comprehensive JUnit Test Suite #7145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
trishajp38-source
wants to merge
6
commits into
TheAlgorithms:master
from
trishajp38-source:improve-factorial
Open
Optimize Factorial Algorithm (Iterative Implementation) and Add Comprehensive JUnit Test Suite #7145
trishajp38-source
wants to merge
6
commits into
TheAlgorithms:master
from
trishajp38-source:improve-factorial
Conversation
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
... iterative factorial with full test suite
@trishajp38-source
trishajp38-source
requested review from
DenizAltunkapan,
alxkm and
yanglbme
as code owners
November 29, 2025 15:37
Codecov Report
✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.91%. Comparing base (d9f2ac8) to head (9041247).
Additional details and impacted files
@@ Coverage Diff @@ ## master #7145 +/- ## ========================================= Coverage 78.90% 78.91% + Complexity 6853 6850 -3 ========================================= Files 769 768 -1 Lines 22668 22665 -3 Branches 4456 4455 -1 ========================================= - Hits 17887 17885 -2 Misses 4067 4067 + Partials 714 713 -1
☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.
🚀 New features to boost your workflow:
- ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
Author
trishajp38-source
commented
Nov 29, 2025
All CI checks have passed.
Formatting has been applied using clang-format.
Please review the PR.
anandfresh
anandfresh
approved these changes
Dec 7, 2025
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.
Summary
This PR improves the existing
Factorialimplementation in thedivideandconquerpackage by replacing the recursive algorithm with an optimized iterative version. The new implementation reduces space complexity, avoids recursion overhead, and prevents stack overflow for moderately large inputs.In addition, this PR adds a comprehensive JUnit test suite to validate correctness, edge cases, performance behavior, and relative improvement compared to the original recursive approach.
✔ Algorithm Improvements
✔ Test Suite Added (
FactorialTest.java)The added JUnit test suite covers:
1. Basic Correctness
IllegalArgumentException2. Performance & Analysis
3. Demonstrating Algorithmic Improvement
Why This PR Is Valuable
Thank you for reviewing this contribution!