start from middle element of first column..perform directed binary search either in corresponding column or row.
On Mon, Jul 18, 2011 at 11:52 PM, ankit sambyal <[email protected]>wrote: > Sry for the above typo. Correct algo > > A more efficient approach : > Suppose the array is M*N > > fun(int i, int j) > if(a[i][j] == x) > return; > mid1=(i+M-1)/2; > mid2=(j+N-1)/2; > > if(abs(a[i][mid1] - x) < abs(a[mid2][j]) - x) > return fun(i,mid1) > else > return fun(mid2,j) > > > > This algo can be easily modified to account for the case in which the > element does not exist > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
