once the array is sorted, it is very easy
have two pointers one on left and one on right take the sum, if sum is
greater, move right one inwards else if less than sum, move left one inwards
do this till sum is found of these two pointers meet
Best Regards
Ashish Goel
Think positive and find
can it be done in O(nlogn)
On Sun, Jun 12, 2011 at 8:42 PM, Ashish Goel ashg...@gmail.com wrote:
once the array is sorted, it is very easy
have two pointers one on left and one on right take the sum, if sum is
greater, move right one inwards else if less than sum, move left one inwards
do
can it be done in O(n)
On Sun, Jun 12, 2011 at 11:00 PM, amit kumar amitthecoo...@gmail.comwrote:
can it be done in O(nlogn)
On Sun, Jun 12, 2011 at 8:42 PM, Ashish Goel ashg...@gmail.com wrote:
once the array is sorted, it is very easy
have two pointers one on left and one on right take
Hi,
For x = 10,11,12,13 it is going in infinite loop.
Your recursive call for binary_search function is going in infinite loop. So
please look in to the logic for binary search function.
And one more thing once you sort the array and after this you can search the
pair in linear time { for
thanx a lot Now it is working for all cases..
On Thu, Jun 9, 2011 at 11:28 AM, varun pahwa varunpahwa2...@gmail.comwrote:
may be now it works for all. please correct me if i am wrong.you haven't
put termination in binary search.
#includeiostream
using namespace std;
void merge(int
we have to find in O(nlgn)
On Thu, Jun 9, 2011 at 10:55 AM, D.N.Vishwakarma@IITR deok...@gmail.comwrote:
#includeiostream
using namespace std;
void merge(int A[],int p,int q,int r)
{
int n1=q-p+1;int n2=r-q;
int L[n1];
int R[n2];
for(int i=0;in1;i++)
L[i]=A[p+i];
for(int j=0;jn2;j++)
may be now it works for all. please correct me if i am wrong.you haven't put
termination in binary search.
#includeiostream
using namespace std;
void merge(int A[],int p,int q,int r)
{
int n1=q-p+1;int n2=r-q;
int L[n1];
int R[n2];
for(int i=0;in1;i++)
L[i]=A[p+i];
for(int j=0;jn2;j++)