paint-brush
How To Search An Element In Sorted Matrix In Linear Timeby@ganeshkumarm1
1,433 reads
1,433 reads

How To Search An Element In Sorted Matrix In Linear Time

by Ganesh Kumar M2mAugust 11th, 2020
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

If x exists, then return its coordinates (i, j), else return (-1, -1). In this example, we are going to search for the value 12 in a sorted matrix M. The worst case time complexity of the above algorithm will be O(O(n x m) = O(n²) when n = m, because we will be iterating all rows and all columns once if x is at the bottom left position (n - 1, 0) If the value is equal to x return (0, m - 1) Move one row down if the current value is less than x, then move one column left.
featured image - How To Search An Element In Sorted Matrix In Linear Time
Ganesh Kumar M HackerNoon profile picture
Ganesh Kumar M

Ganesh Kumar M

@ganeshkumarm1

Software Engineer at OptumInsight India

Learn More
LEARN MORE ABOUT @GANESHKUMARM1'S
EXPERTISE AND PLACE ON THE INTERNET.
L O A D I N G
. . . comments & more!

About Author

Ganesh Kumar M HackerNoon profile picture
Ganesh Kumar M@ganeshkumarm1
Software Engineer at OptumInsight India

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite