edited by
854 views
3 votes
3 votes
Given a 2D array X[m][n] which has m rows and n columns. The array X is row wise and column wise sorted (i.e) each individula row and column is sorted. What is the complexity to search an element in this array

a)O(m*n)

b)O(m2) or O(n2)

c)O(log2(m*n))

d)O(m+n)
edited by

2 Answers

0 votes
0 votes
option D
0 votes
0 votes
You can binary search on each column.This might seem O(logm*logn) but it actually is min O(m*logn,n*logm).The answer can be both A and B.
edited by

Related questions

1 votes
1 votes
0 answers
1
0 votes
0 votes
1 answer
2
0 votes
0 votes
3 answers
3
0 votes
0 votes
1 answer
4
Deepalitrapti asked Sep 11, 2018
352 views