Search in a sorted 2D matrix (Stored in row major order) Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Given an integer 'K' and a row-wise sorted 2-D Matrix i.e. the matrix has the following properties: Integers in each row are sorted from left to right.The first integer of each row is greater than the last integer of the previous row.The task is to find whether the integer 'K' is present in the matrix or not. If present then print 'Found' else print 'Not found'.Examples: Input: mat = { {1, 3, 5, 7}, {10, 11, 16, 20}, {23, 30, 34, 50}} K = 3Output: FoundInput: mat = { {1, 3, 5, 7}, {10, 11, 16, 20}, {23, 30, 34, 50}} K = 13Output: Not foundPlease refer Search element in a sorted 2D array for three different approaches to solve this problem.Please refer Searching Algorithms for 2D Arrays (Matrix) for searching in an unsorted, sorted and semi-sorted arrays. Comment More infoAdvertise with us Next Article Search in matrix where only individual columns are sorted G geekoverflow Follow Improve Article Tags : Divide and Conquer Matrix DSA Practice Tags : Divide and ConquerMatrix Similar Reads Search in row wise sorted matrix Given a row-wise sorted matrix mat[][] and an integer x, the task is to check if x is present in mat[][] or not. Note that there is no ordering among column elements.Examples:Input: x = 9, mat[][] = [[3, 4, 9], [2, 5, 6], [9, 25, 27]]Output: trueExplanation: mat[0][2] is equal to 9.Input: x = 56, ma 6 min read Search in a row wise and column wise sorted matrix Given a matrix mat[][] and an integer x, the task is to check if x is present in mat[][] or not. Every row and column of the matrix is sorted in increasing order.Examples: Input: x = 62, mat[][] = [[3, 30, 38], [20, 52, 54], [35, 60, 69]]Output: falseExplanation: 62 is not present in the matrix.Inpu 14 min read Search element in a sorted matrix Given a sorted matrix mat[][] of size nxm and an element x, the task is to find if x is present in the matrix or not. Matrix is sorted in a way such that all elements in a row are sorted in increasing order and for row i, where 1 <= i <= n-1, the first element of row i is greater than or equal 13 min read Find median in row wise sorted matrix Given a row-wise sorted matrix mat[][] of order n * m, where the number of rows and columns are always odd. The task is to find the median of the matrix.Note: Median is the middle number in a sorted ascending or descending list of numbers. In case of an even number of elements return the left median 15+ min read Search in matrix where only individual columns are sorted Given an n * m semi-sorted 2D matrix, mat[][] where each column is individually sorted in ascending order but the rows are not sorted, and a target element x. The task is to find the position (row and column index) of x in the matrix. If the element is not found, return -1.Examples: Input: mat[][] = 7 min read Print all elements in sorted order from row and column wise sorted matrix Given an n x n matrix, where every row and column is sorted in non-decreasing order. Print all elements of the matrix in sorted order. Example: Input: mat[][] = { {10, 20, 30, 40}, {15, 25, 35, 45}, {27, 29, 37, 48}, {32, 33, 39, 50}, };Output: 10 15 20 25 27 29 30 32 33 35 37 39 40 45 48 50 Recomme 15+ min read Like