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.
