July 31, 2024 |26.9K Views

    Search in a row wise and column wise sorted matrix

      Share   Like
    Description
    Discussion

    Given an n x n matrix and a number x, find the position of x in the matrix if it is present in it. Otherwise, print “Not Found”. In the given matrix, every row and column is sorted in increasing order. The designed algorithm should have linear time complexity.

    Example:

    Input: mat[4][4] = { {10, 20, 30, 40},
                                  15, 25, 35, 45},
                                  {27, 29, 37, 48},
                                {32, 33, 39, 50}}
              x = 29
    Output: Found at (2, 1)
    Explanation: Element at (2,1) is 29

    Search in a row wise and column wise sorted matrix : https://www.geeksforgeeks.org/search-in-row-wise-and-column-wise-sorted-matrix/