Java
Java copied to clipboard
Add Search a 2D Matrix algorithm
Description
This pull request adds the Search a 2D Matrix algorithm to the directory
src/main/java/com/thealgorithms/matrix/.
This algorithm solves the well-known problem where each row of the matrix is sorted,
and the first element of each row is greater than the last element of the previous row.
A binary search is applied on the virtual 1D representation of the matrix to achieve
O(log(m*n)) time complexity.
A detailed explanation of the problem can be found here:
https://leetcode.com/problems/search-a-2d-matrix/
This implementation includes:
- Clean binary search logic
- JavaDoc-style documentation
- Proper placement within the
matrixpackage
Type of Change
- [x] New Algorithm (non-breaking addition)
- [x] Enhancement to the matrix category
Checklist
- [x] I have read
CONTRIBUTING.md. - [x] This pull request is all my own work.
- [x] File name follows PascalCase.
- [x] Function and variable names follow Java coding conventions.
- [x] Added the required URL reference in the JavaDoc comment.
- [x] Code is formatted with
clang-formatas required.