Nice solution by Manish. But can there be a more efficient solution? On Tue, Jul 26, 2011 at 8:17 PM, Puneet Gautam <[email protected]>wrote:
> 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 <[email protected]> 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 <[email protected]> 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 [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. > >> > >> > > > > > > -- > > > ___________________________________________________________________________________________________________ > > > > 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 [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. > > -- Nikhil Gupta Senior Co-ordinator, Publicity CSI, NSIT Students' Branch NSIT, New Delhi, India -- 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.
