The input is an array S containing n real numbers, and a real number
x, Design an algorithm to determine whether there are 2 elements of S
whose sum is exactly x. and onemore thing is that S is in sorted
order.
I got the solution with the complexity of O(n logn) but I am searching
for an algo. on O(n) complexity.
My solution is like this,
for each element k in S // There are n element so iterates n
times
{
k = k - x;
if( BinarySearch(k,S) ) // complexity is O ( log n )
{
found an elemnt
break;
}
}
So overall complexity is O ( n logn).
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---