Java icon indicating copy to clipboard operation
Java copied to clipboard

Add Search a 2D Matrix algorithm

Open AHVSSATHVIK opened this issue 2 weeks ago • 2 comments

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 matrix package

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-format as required.

AHVSSATHVIK avatar Nov 25 '25 06:11 AHVSSATHVIK