Add basic recursion algorithms
Summary of Changes
This pull request adds a new package recursion under com.thealgorithms to implement basic recursion algorithms, which are fundamental for understanding more complex techniques such as dynamic programming.
Changes in Detail:
- Subsets.java: Generates all subsets of a string using recursion.
- Fibonacci.java: Computes the nth Fibonacci number using a recursive approach.
- Factorial.java: Recursively calculates the factorial of a number.
- Permutations.java: Recursively generates all permutations of a string.
- TowerOfHanoi.java: Solves the Tower of Hanoi problem for n disks using recursion.
Checklist:
- [x] I have read CONTRIBUTING.md.
- [x] This pull request is all my own work -- I have not plagiarized it.
- [x] All filenames are in PascalCase.
- [x] All functions and variable names follow Java naming conventions.
- [x] All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
- [x] All new code is formatted with
clang-format -i --style=file src/main/java/com/thealgorithms/recursion/Subsets.java clang-format -i --style=file src/main/java/com/thealgorithms/recursion/Fibonacci.java clang-format -i --style=file src/main/java/com/thealgorithms/recursion/Factorial.java clang-format -i --style=file src/main/java/com/thealgorithms/recursion/Permutations.java clang-format -i --style=file src/main/java/com/thealgorithms/recursion/TowerOfHanoi.java.
Additional Notes
This proposal aims to fill the gap by introducing basic recursion algorithms, which are crucial for building a strong foundation for understanding advanced topics like dynamic programming.
Codecov Report
Attention: Patch coverage is 0% with 30 lines in your changes missing coverage. Please review.
Project coverage is 52.19%. Comparing base (
7f60d57) to head (e5a929d). Report is 129 commits behind head on master.
Additional details and impacted files
@@ Coverage Diff @@
## master #5505 +/- ##
============================================
- Coverage 52.28% 52.19% -0.10%
- Complexity 3256 3257 +1
============================================
Files 525 530 +5
Lines 15185 15215 +30
Branches 2887 2888 +1
============================================
+ Hits 7940 7941 +1
- Misses 6920 6950 +30
+ Partials 325 324 -1
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
The factorial is already implemented here https://github.com/TheAlgorithms/Java/blob/842ff5294f5e97dfd1e4c09f9d9e01a89ac16e32/src/main/java/com/thealgorithms/maths/Factorial.java#L3 Please also check other algorithms for duplicates, also fix build PR check
These algorithms already exist:
TowerOfHanoi.java,Permutation.java,GenerateSubsets.java,- factorial and Fibonacci numbers are implemented in several ways.
If you want to contribute, you can do the following:
- find any class, which has the
mainmethod, - remove it (i.e. the
mainmethod), - add proper tests for this class.
Please work on one class in single PR.