sort using counting sort or quickselect

now a and b are less than c

so find c first
suppose c's index is k
the start two indexes i=0 and j=k-1, if a[i]+a[j] ==a[k] return these
numbers, else add elements at i,j if the sum is greater than c reduce j, if
less than c increase i

alternatively sort array, find index of c, make a BST or a hash table,
starting from index 0 of the sorted array, find c-a....this is overhead on
second thoughts, i will proceed with first approach


Best Regards
Ashish Goel
"Think positive and find fuel in failure"
+919985813081
+919966006652


On Wed, Jul 14, 2010 at 9:55 PM, siddharth shankar <
siddharth.shanka...@gmail.com> wrote:

> O ( n^2 ) soln can be done ....
> step :
>
> 1 . sort array in n*log(n) .
> 2.  for every "C" from last find two number A & B such that A+B=C ...   O(
> n^2 )
> Total :- O(N^2)
>
> can we improve it further ?? .... any help please ....
>
> On Wed, Jul 14, 2010 at 10:57 AM, Debajyoti Sarma <
> sarma.debajy...@gmail.com> wrote:
>
>> An array contains the set of positive integer. Find the largest number
>> c such that c=a+b where a,b,c are distinct number of the set?
>> [Consider , reducing complexity]
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algoge...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>>
>
>
> --
> siddharth shankar
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algoge...@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com>
> .
> 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 algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to