0% found this document useful (0 votes)
36 views7 pages

Assignment No 2 Saddle Point

Sp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views7 pages

Assignment No 2 Saddle Point

Sp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Assignment no 2

Aim : Write a Python program that determines the location of a saddle point of matrix if one
exists. An m x n matrix is said to have a saddle point if some entry a[i][j] is the smallest value
in row i and the largest value in j.
Pre-requisite:
1) Knowledge of representing matrix in Python
2) Knowledge of different operations that can be performed on matrix
Objectives:
To understand the concept of saddle point in matrix
To implement python program for saddle point
Input : N x N Matrix to be provided
Output: the location of a saddle point of matrix

Theory:

Array: Arrays is a set of consecutive memory locations which contains similar data
elements.
If we intend to store a group of data together in sequential manner in computers memory,
then array can be one of the possible data structures.
An array is a finite ordered collection of homologous data elements which provides direct
access to any of its elements.

set of pair such that with each index


a value is associated
eg:
x=cars[0]
where x=variable 0=index
1) 1D Array: One dimensional array is also called as single dimensional array.
Accessing its elements involves a single subscript which can either represent a row or
column Index.
example: int Array name [10] → 1D array with 10 int.
2) 2D Array – The two dimensional array should be in row column form.
They can be represented in two ways
a) Row major representation.
b) Column major representation...
Example: a [i][j];

4] Matrix representation using Array:


2D Array is matrix used to represent sparse matrix
Row: index of row where non zero element is Located
Colomn: Index of column where non Zero element is located.
Value: Value of non-zero element located at index. [row, column]

* Saddle point

A saddle point in a matrix element is smallest in row and largest


element in its column.
Eg:
12 3
A= 4 5 6
789
- A[3][0] is a saddle point
Def: A matrix is said saddle point if some entry in it eg A[i][j] is smallest in its row and biggest
in its column.
- Matrix can have zero or one Saddle point

Algorithm for accept and display matrix :


step1: Start procedure
Step2 : Define function accept matrix.
step3: Input no. of rows and columns
Step 4: Initiate empty list mat
Step 5: Repeat step 6 & 7 until i = no⋅ rows.
Step 6: initiate empty list a
Step 7: append elements till j= no. of column
Step 8: append list to matrix mat ()
Step 9: print mat ()
step 10: End.

Algorithm for saddle point.


Step1: start.
Step2: Define function saddle point.
step3: set F=0
step4: Repeat step 5 and 6 , till i=r.
Step 5: min r=mat [i] [0]
Step 6: Run loop.
Step 7: set F=0
Sep 8: repeat steps 9 and 10 till j=i.
step 9: min r >= mat [i][j]
step 10: max = mat [0][t]
step11: Given range for K till r.
step 12: if it runs for max = mat [K] [t]
print it is saddle point.
Step13 else print no saddle
Step14: End.
Flowchart for accept and display matrix:
Flowchart for saddle point:
Conclusion :

By this way, we can determine location of saddle point in matrix successfully.

You might also like