Assuming that both  the array are sorted.

For all elements of array1
   Pick up an element from array1.
   Subtract that element from the number passed.
   The difference you got search that number in second array using binary
search.
   If elements found come out of the loop and return 1 else return 0.

I think this approach will take O(nlogn) time.

If the array are not sorted then use linear search. Then this approach will
take O(n^2) time.

On Fri, Jul 23, 2010 at 12:01 AM, vijay <[email protected]> wrote:

> You have 2 arrays of integer. You have to write a function, which take
> an integer as input and returns bool. Example array 1 has {1,5,10}
> array 2 has {2,5,9}. Func(3) should return true, since 1 (from array
> 1) +2 (from array 2) =3 ( i.e summation of 2 numbers (1 from each
> array) is equal to 3). Func(13) should return false
>
> --
> 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.
>
>


-- 
regards

Apoorve Mohan

-- 
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.

Reply via email to