feat: Add LU decomposition algorithm for matrices using Doolittle's algorithm
Description
This PR implements the LU decomposition algorithm for square matrices as requested in issue #6833.
Changes
- Implements LU decomposition using Doolittle's method
- Decomposes square matrix A into L (lower) and U (upper) triangular matrices
- Includes comprehensive test cases with edge case handling
- Time complexity: O(n³), Space complexity: O(n²)
- Resolves #6833
Algorithm Details
-
Purpose: Decomposes a square matrix A into L × U where:
- L is a lower triangular matrix with 1s on diagonal
- U is an upper triangular matrix
- Use cases: Solving linear equations, computing determinants, finding matrix inverses
- Method: Doolittle's algorithm
- Time Complexity: O(n³)
- Space Complexity: O(n²)
Testing
- ✅ Basic 3x3 matrix decomposition (from issue example)
- ✅ Identity matrix decomposition
- ✅ 2x2 matrix decomposition
- ✅ Non-square matrix error handling
- ✅ Empty matrix error handling
- ✅ Singular matrix error handling
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 path/to/your/file.java
Closes #6833
Codecov Report
:x: Patch coverage is 50.00000% with 27 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 78.45%. Comparing base (f693c44) to head (aa709b7).
| Files with missing lines | Patch % | Lines |
|---|---|---|
| ...java/com/thealgorithms/matrix/LUDecomposition.java | 50.00% | 27 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## master #7101 +/- ##
============================================
- Coverage 78.50% 78.45% -0.06%
- Complexity 6752 6757 +5
============================================
Files 759 759
Lines 22402 22432 +30
Branches 4400 4407 +7
============================================
+ Hits 17587 17598 +11
- Misses 4109 4129 +20
+ Partials 706 705 -1
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
This pull request has been automatically closed because its workflows or checks failed and it has been inactive for more than 14 days. Please fix the workflows and reopen if you'd like to continue. Merging from main/master alone does not count as activity.