Re: [algogeeks] Sum to K problem

2011-07-02 Thread keyan karthi
http://en.wikipedia.org/wiki/Subset_sum_problem this should help u :) knapsack like dp :) On Mon, Jun 20, 2011 at 11:55 AM, Navneet Gupta wrote: > Given a set of integers , find a set of numbers such that they sum to a > given number k . > Notice

Re: [algogeeks] Sum to K problem

2011-06-20 Thread Harshal
The problem is NP. Complexity using DP will be O(nk), where n is number of elements and k is required sum. S[0]=true; //choose no element S[1...k] = false; for each number i in your input for s = k downto i if ( S[s - i] == true ) S[s] = true; S[s] = true indicates a sum of i

Re: [algogeeks] Sum to K problem

2011-06-20 Thread Navneet Gupta
Ideally, yes it can. Though i would be happy even if someone gives a good answer for non-negative values. On Mon, Jun 20, 2011 at 6:28 PM, Akshata Sharma wrote: > @Navneet: does the set contains negative elements also? > > On Mon, Jun 20, 2011 at 12:26 PM, pacific :-) wrote: >> >> @vaibhav : Ple

Re: [algogeeks] Sum to K problem

2011-06-20 Thread Akshata Sharma
@Navneet: does the set contains negative elements also? On Mon, Jun 20, 2011 at 12:26 PM, pacific :-) wrote: > @vaibhav : Please note that more than two numbers can sum upto k. > > On Mon, Jun 20, 2011 at 12:21 PM, vaibhav shukla > wrote: > >> sort the array using merge sort : order nlogn >> ta

Re: [algogeeks] Sum to K problem

2011-06-19 Thread pacific :-)
@vaibhav : Please note that more than two numbers can sum upto k. On Mon, Jun 20, 2011 at 12:21 PM, vaibhav shukla wrote: > sort the array using merge sort : order nlogn > take the first element,subtract it with 'k' , then search the result using > binary search in rest of the array : order nlogn

Re: [algogeeks] Sum to K problem

2011-06-19 Thread oppilas .
Vaibhav, We are not finding two numbers with sum "X". Here we are talking about subset. :) @Navneet Please see this link http://www-ti.informatik.uni-tuebingen.de/~reinhard/krypto/English/4.5.1.e.html PS: You might have seen it before. In that case ignore it. ~ Oppilas On Mon, Jun 20, 2011 at

Re: [algogeeks] Sum to K problem

2011-06-19 Thread vaibhav shukla
sort the array using merge sort : order nlogn take the first element,subtract it with 'k' , then search the result using binary search in rest of the array : order nlogn hence u get two elements which sum up to K in order nlogn On Mon, Jun 20, 2011 at 12:14 PM, Navneet Gupta wrote: > Right, in th

Re: [algogeeks] Sum to K problem

2011-06-19 Thread Navneet Gupta
Right, in the worst case, complexity with be O(2^N). So what are the possible optimizations here? Would building pre-computed data structures with intermediate sum values help in finding such pairs in less complexity? I think then we can apply dynamic programming to find such pairs. On Mon, Jun

Re: [algogeeks] Sum to K problem

2011-06-19 Thread oppilas .
I think its a NP problem. The solution complexity can go up O(2^N) in worst case. On Mon, Jun 20, 2011 at 11:55 AM, Navneet Gupta wrote: > Given a set of integers , find a set of numbers such that they sum to a > given number k . > Notice the set of numbers can have 2 or more than 2 numbers. > >

[algogeeks] Sum to K problem

2011-06-19 Thread Navneet Gupta
Given a set of integers , find a set of numbers such that they sum to a given number k . Notice the set of numbers can have 2 or more than 2 numbers. --Navneet -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send emai