Add generic and sorted 2D matrix search utilities#7217
Add generic and sorted 2D matrix search utilities#7217GziXnine wants to merge 16 commits intoTheAlgorithms:masterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7217 +/- ##
============================================
+ Coverage 79.09% 79.15% +0.06%
- Complexity 6973 7005 +32
============================================
Files 783 785 +2
Lines 22950 23017 +67
Branches 4512 4536 +24
============================================
+ Hits 18152 18219 +67
Misses 4077 4077
Partials 721 721 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…rays, and null comparator
|
Hi @DenizAltunkapan, @yanglbme, @alxkm, I noticed that my pull request (#7217) has all checks passed, but it still cannot be merged. Thank you for your time and guidance! |
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution! |
|
Please reopen this pull request once you have made the required changes. If you need help, feel free to ask in our Discord server or ping one of the maintainers here. Thank you for your contribution! |
clang-format -i --style=file path/to/your/file.javaSummary
This PR adds two reusable 2D matrix search utilities under
com.thealgorithms.matrix.SearchSortedMatriximplements Saddleback (“staircase”) search for matrices whose rows and columns are sorted in ascending order, providing an efficientO(m+n)membership check without flattening.SearchMatrixprovides a general-purposecontainsmethod for arbitraryT[][]matrices with no ordering assumptions, using a straightforward linear scan.Details
SearchSortedMatrixnull/empty matrices.O(m+n), spaceO(1).SearchMatrixT[][].Objects.equals.O(m*n), spaceO(1).Tests
Adds unit coverage for both algorithms:
SearchSortedMatrixTestSearchMatrixTestThese tests cover typical found/not-found cases and edge conditions (null/empty input, jagged matrices, and null rows/elements where applicable).
Closes #6622