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.