yup .. I know... I missed dat out...! But say , the array is random sorted, then is there an O(N) solution....?
On 7/26/11, Dipankar Patro <dip10c...@gmail.com> wrote: > Puneet, > you missed out the 'sorted' part of array. Your code works fine for > randomized array. > > +1 to Manish's solution. I had the same algo :) > > On 26 July 2011 00:33, Puneet Gautam <puneet.nsi...@gmail.com> wrote: > >> let k=a+b >> >> run in two loops >> >> for(i=0;((i<n) && (a[i]<k));i++) >> for(j=i+1;a[j]<=(k-a[i]);j++) >> if(a[j]==k-a[i]) >> do break from both outer n inner loops; >> diplay a[i] n a[j] >> >> Time complexity:O(n^2) worst case >> shud take O(nlgn) on an average >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> >> > > > -- > ___________________________________________________________________________________________________________ > > Please do not print this e-mail until urgent requirement. Go Green!! > Save Papers <=> Save Trees > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.