@Dheeraj: This is a great solution. My first thought has complexity
O(n^3) and uses O(1) extra space. For your algorithm, sorting an array
of size n^2 would be O(n^2 log n), so your algorithm has complexity
O(n^2 log n) and uses extra space of size O(n^2). We can see the
tradeoff of space for complexity.

Dave

On Aug 27, 1:11 pm, Dheeraj Sharma <dheerajsharma1...@gmail.com>
wrote:
> create an array of all possible PAIR sums..that would be done in
> O(n^2)..sort it..O(log(n))now..search this array for two pairs..that sum to
> the required value..
> this can be done by maintaining two index..one at the lowest value..one at
> the highest value..and moving them accordingly..(if sum of pair exceeds
> given value..move up highest value pointer..else move down..lowest value
> pointer)
>
> On Sat, Aug 27, 2011 at 10:59 PM, tech coder <techcoderonw...@gmail.com>wrote:
>
> > Given an array A[] and a integer num. Find four no.s in the array whose sum
> > is equal to given num.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Algorithm Geeks" group.
> > To post to this group, send email to algogeeks@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.
>
> --
> *Dheeraj Sharma*
> Comp Engg.
> NIT Kurukshetra
> +91 8950264227

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@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