@saurabh.nsit: Consider the following array:
1 2 6 7 2 3 7 8 4 5 8 9 5 7 9 10 And the item to be searched is 6. As I understand it, using your approach you will search 6 in only the second and third row, which will not give the correct solution. Hope this clears a few doubts. @Gene: Analysing the complexity of ur algo: T(n) = 3*T(n/2) + O(1) which is n^(log_2(3)) = n^1.6. Cheers Nikhil Jindal On Sun, Sep 26, 2010 at 11:14 PM, saurabh singh <[email protected]>wrote: > As you mentioned ultimately element to be searched should either be in row > 'i' (ahead of [i,i] element) or in row i+1 (before [i+1,i+1] element). Since > each row contain numbers in sorted order so u can do binary search on these > two rows and ultimately the complexity will be O(logn) only > > On Sun, Sep 26, 2010 at 7:34 PM, Nikhil Jindal <[email protected]>wrote: > >> >> >> On Tue, Sep 21, 2010 at 6:05 PM, saurabh singh >> <[email protected]>wrote: >> >>> solution 1: >>> use concept of quad-tree and do binary search in that tree >>> >>> solution 2: >>> do binary search on major diagonal. ultimately u will narrow down to >>> search for element in 2 rows. in these two rows again do binary search. >>> >> >> How do you narrow down to two rows? Please explain. >> By searching on the diagonal, you get two elements such that one is lesser >> than the number being searched for and the next is greater. let them be i,i, >> and i+1,i+1. >> >> So you remove the array from 0,0 to i,i and from i+1,i+1 to n-1,n-1. But >> the number could be anywhere in the rest of the array >> >> >>> >>> any solution will lead you to O(log(n)) time >>> >>> >>> On Tue, Sep 21, 2010 at 5:10 PM, jagadish <[email protected]>wrote: >>> >>>> Hi all, >>>> Given a 2d array which is sorted row wise and column wise as well, >>>> find a specific element in it in LESS THAN O(n). >>>> PS: an O(n) solution would involve skipping a column or a row each >>>> time from the search and moving accordingly. >>>> Solution less than O(n) is desirable! >>>> >>>> -- >>>> 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]<algogeeks%[email protected]> >>>> . >>>> For more options, visit this group at >>>> http://groups.google.com/group/algogeeks?hl=en. >>>> >>>> >>> >>> >>> -- >>> Thanks & Regards, >>> Saurabh >>> >>> -- >>> 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]<algogeeks%[email protected]> >>> . >>> For more options, visit this group at >>> http://groups.google.com/group/algogeeks?hl=en. >>> >> >> Please access the attached hyperlink for an important electronic >> communications disclaimer: >> http://dce.edu/web/Sections/Standalone/Email_Disclaimer.php >> >> >> >> -- >> >> >> 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] >> <algogeeks%[email protected]>. >> >> >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> >> >> > > > -- > Thanks & Regards, > Saurabh > > -- > 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]<algogeeks%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > Please access the attached hyperlink for an important electronic communications disclaimer: http://dce.edu/web/Sections/Standalone/Email_Disclaimer.php -- 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.
