4

Given a set of integers S:

How can the set be divided into k parts such that the sum of each part is minimal? Please give also a C implementation.

Example:

S = {1, 2, 3, 4, 5, 6} and k = 3

The partition

 S1 = {1, 6}
 S2 = {2, 5}
 S3 = {3, 4}

has the property that the sum of each partition is minimal.

Chris Gerken
  • 16,221
  • 6
  • 44
  • 59
edgarmtze
  • 24,683
  • 80
  • 235
  • 386
  • 1
    Looks like Homework to me... :D – fresskoma Mar 21 '11 at 22:04
  • Nope, just curious to know your ideas or algorithms to compute this as fast as posiible, could be just pseudocode instead of `C` code – edgarmtze Mar 21 '11 at 22:06
  • What if some parts have different sums. Are we trying to minimize the maximum sum of the partitions? – Null Set Mar 21 '11 at 22:11
  • No, we're trying to divide the numbers as "fair as possible" so that biggest difference between two partition sums is as small as possible. Read the introduction on the page I linked, it's very good at explaining the problem. – orlp Mar 21 '11 at 22:15

2 Answers2

2

This page describes the problem fairly well and even provides pseudocode for an algorithm:

http://www8.cs.umu.se/kurser/TDBAfl/VT06/algorithms/BOOK/BOOK2/NODE45.HTM

orlp
  • 112,504
  • 36
  • 218
  • 315
  • I don't think this answer is correct, the algorithm you suggest solves it assuming the arrangement is kept the same. – st0le Mar 28 '11 at 11:44
1

Determine min, max in the given list and form a pair. Repeat until the list is exhausted.

Intuitively it seems it will ensure the desired result, but not sure though!

Rushikesh
  • 163
  • 8