I think we can sort the elements first and then start scanning from both ends of the array. All the pairs can be found this way and the complexity will be O(nlogn).
On Sun, Oct 24, 2010 at 6:08 AM, Avik Mitra <[email protected]> wrote: > We can follow an algorithm described below. > > Set found:= FALSE > For each number n belong to array A.and until found != TRUE > For each number k in A not equal to n, do: > if k+n == m then > output "The pairs are n and k" > Set found:=TRUE. > Break. > > The running time will be of O(n^2). > > -- > 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. > > -- 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.
