[algogeeks] Re: Minimum sum of Array

2013-01-07 Thread Don
You want to partition the array A into to subsets S1 and S2 such that you minimize |Sum(S1)-Sum(S2)|. The optimal sum for the subsets is S=SUM(A)/2 Use DP to build a matrix P: P[i][j] = 1 if some subset of {A[0]..A[i]} has a sum of j, 0 otherwise Now find a value of i such that P[n][i] = 1

[algogeeks] Re: Minimum sum of Array

2013-01-07 Thread Don
Note that you don't need to store the entire P matrix. You really just need the last column. Don On Jan 7, 10:29 am, Don dondod...@gmail.com wrote: You want to partition the array A into to subsets S1 and S2 such that you minimize |Sum(S1)-Sum(S2)|. The optimal sum for the subsets is

Re: [algogeeks] Re: perfect square condition checking....

2013-01-07 Thread bala bharath
@Don, Can u explain with an Example...? With regards, Balasubramanian Naagarajan, Chettinad College of Engg Tech. On Sat, Jan 5, 2013 at 1:48 PM, Malathi malu@gmail.com wrote: Check this. It might help.

Re: [algogeeks] Re: Minimum sum of Array

2013-01-07 Thread Nikhil Karnwal
@ Don but ur's solution complexity is O(S*N) which is large in case of large N and large numbers. Like in case of s=100 and N=10^5. Correct me if I am wrong. Nikhil Karnwal On Mon, Jan 7, 2013 at 9:04 PM, Don dondod...@gmail.com wrote: Note that you don't need to store the entire P matrix.

Re: [algogeeks] Linked List question

2013-01-07 Thread Doom
Thank you for the code snippet. What I don't understand is if( (double)rand() / RAND_MAX 1 / k ) Here, Why do we use less than inequality? Why won't Udit's solution of just using the minimum random number work? On Tuesday, 1 January 2013 20:57:47 UTC+5:30, Dave wrote: @Doom: Yes. It is

[algogeeks] Suggested the Data Structure to implement the solution in O(1)

2013-01-07 Thread Nishant Pandey
Give a Data structure to store Name-value pair like name-age abc,12 xyz,34... such than insert(name,value), value = search(name), name = nthentry(n), delete(name); all can be perfomed in O(1). Note:- after deletion order should be maintained.Ex. ds,12 df,78 teu,54 etr,12 If delete(df) is called