How to divide a set into two subsets such that difference between the sum of numbers in two sets is minimal?

前端 未结 18 706
攒了一身酷
攒了一身酷 2020-11-27 10:55

Given a set of numbers, divide the numbers into two subsets such that difference between the sum of numbers in two subsets is minimal.

T

18条回答
  •  执念已碎
    2020-11-27 11:53

    Many answers mentioned about getting an 'approximate' solution in a very acceptable time bound . But since it is asked in an interview , I dont expect they need an approximation algorithm. Also I dont expect they need a naive exponential algorithm either.

    Coming to the problem , assuming the maximum value of sum of numbers is known , it can infact be solved in polynomial time using dynamic programming. Refer this link https://people.cs.clemson.edu/~bcdean/dp_practice/dp_4.swf

提交回复
热议问题