Re: [algogeeks] Re: finding whether sum of two numbers of array is equal to given number or not ? plz tell why my this is not working for x=10,11,13 values

2011-06-12 Thread Ashish Goel
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

Re: [algogeeks] Re: finding whether sum of two numbers of array is equal to given number or not ? plz tell why my this is not working for x=10,11,13 values

2011-06-12 Thread amit kumar
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

Re: [algogeeks] Re: finding whether sum of two numbers of array is equal to given number or not ? plz tell why my this is not working for x=10,11,13 values

2011-06-12 Thread amit kumar
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

Re: [algogeeks] Re: finding whether sum of two numbers of array is equal to given number or not ? plz tell why my this is not working for x=10,11,13 values

2011-06-11 Thread Amit Chauhan
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

Re: [algogeeks] Re: finding whether sum of two numbers of array is equal to given number or not ? plz tell why my this is not working for x=10,11,13 values

2011-06-09 Thread D.N.Vishwakarma@IITR
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

[algogeeks] Re: finding whether sum of two numbers of array is equal to given number or not ? plz tell why my this is not working for x=10,11,13 values

2011-06-08 Thread D.N.Vishwakarma@IITR
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++)

Re: [algogeeks] Re: finding whether sum of two numbers of array is equal to given number or not ? plz tell why my this is not working for x=10,11,13 values

2011-06-08 Thread varun pahwa
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++)