retagged by
320 views

1 Answer

1 votes
1 votes

answer will be $O(m+n) .$

 if we search one by one element which will take $O(m*n)$.but we can do better because every row and column is sorted in increasing order ,we can take advantage of that property.

step 1: search from right most element ( assume p) of array ,which is greater than every other element of row.we can move now left or right according to the element (assume  element  x is being searched)

step 2: take loop -if p = x then return position of  p 

                              if p>x then go left else go down.

for example -$\begin{bmatrix} 10 & 20 & 30 &40 \\ 11& 22& 33&44 \\ 21 & 34& 38& 50\\ 31 & 39 & 45& 60 \end{bmatrix}$ soppose we are searching for 34.so we will start from 40 and 40>34 so go left ,now we have 30 which less than 34 so go down ,now we have 33 which is less than 34 so go down,now we have 38 which is greater than 34 so go left hence we got our element 34.so in $ O(m+n) $ we can search our element.

Answer:

Related questions

1.5k
views
3 answers
0 votes
Subham Nagar asked Mar 20, 2018
1,510 views
An array $'A'$ has $n$ distinct integers. What is the tightest time complexity to check $A[i]=i$ for some $i$. Consider all elements of array within range from $1$ to $n$.$O(n^2) $O(1)$O(n)$O(logn)$
322
views
1 answers
1 votes
A_i_$_h asked Jul 24, 2017
322 views
array has n elements and we need to sort them in non decreasing order as follows. first find minimum, remove this element from the array and find minimum of ... and so on until array becomes emplty . In best case how many comparisons needed
527
views
1 answers
0 votes
Rohan Mundhey asked Nov 9, 2016
527 views
Consider an array contains n integers, each integer belongs to {-1, 0, 1}. What is the best case time complexity to sort an array?
807
views
1 answers
0 votes
Daniyal89 asked Sep 30, 2018
807 views
Ans given is option-B