Java icon indicating copy to clipboard operation
Java copied to clipboard

Add basic recursion algorithms

Open shivammm21 opened this issue 1 year ago • 2 comments

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.

shivammm21 avatar Oct 01 '24 15:10 shivammm21

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.

Files with missing lines Patch % Lines
...java/com/thealgorithms/recursion/TowerOfHanoi.java 0.00% 8 Missing :warning:
...java/com/thealgorithms/recursion/Permutations.java 0.00% 7 Missing :warning:
...main/java/com/thealgorithms/recursion/Subsets.java 0.00% 7 Missing :warning:
...in/java/com/thealgorithms/recursion/Factorial.java 0.00% 4 Missing :warning:
...in/java/com/thealgorithms/recursion/Fibonacci.java 0.00% 4 Missing :warning:
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.

codecov-commenter avatar Oct 01 '24 15:10 codecov-commenter

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

siriak avatar Oct 02 '24 17:10 siriak

These algorithms already exist:

If you want to contribute, you can do the following:

  • find any class, which has the main method,
  • remove it (i.e. the main method),
  • add proper tests for this class.

Please work on one class in single PR.

vil02 avatar Oct 03 '24 13:10 vil02