Explore
ProGrad Programs
About Us

Edit
Reply




Edit

Program to find the saddle point coordinates in a given matrix | Face Prep

Published on 10 Mar 2020

Program to find the saddle point coordinates in a given matrix is discussed here.A saddle point is an element of the matrix, which is the minimum element in its row and the maximum in its column.


For example, consider the matrix given below

1 2 3

Mat[3][3] = 4 5 6

7 8 9

Here, 7 is the saddle point because it is the minimum element in its row and maximum element in its column.

saddle point coordinates in a matrix

Algorithm to to find the saddle point coordinates in a given matrix


  1. Input the matrix from the user.
  2. Use two loops, one for traversing the row and the other for traversing the column.
  3. If the current element is the minimum element in its row and maximum element in its column, then return its coordinates.
  4. Else, continue traversing.


Program to find the saddle point coordinates in a given matrix is given below.


C
C++
Java
Python 3

Output
Enter the square matrix order : 3
Input the matrix : 1 2 3 4 5 6 7 8 9
The matrix is :
1 2 3
4 5 6
7 8 9
Saddle point (3,0) : 7


Time complexity: O(n^2)


Recommended Programs







If you have any feedback about this article and want to improve this, please write to enquiry@faceprep.in