The subset sum problem

A demo applet by Frits Beukers accompanying the CWI teacher's vacation course 1999, Onbewezen Vermoedens (Unproved Conjectures)

Given a sequence of positive integer numbers S and a target integer t, one is asked to verify whether there exists a subsequence of S whose elements add up to t. Lacking any systematic general purpose algorithm, all we can do is try all possibilities. This is exactly what the applet does. In the upper boxes we can fill in the desired number of elements of S, a maximum for them and a target number. Pressing the "New numbers" generates a set S with the given cardinality and upper bound for the elements. "Start" then begins the trial and error method. Whenever a solution is found the solution counter is raised by one and the numbers to be added are highlighted in light blue.

While playing with the program one soon finds that a set S of 20 elements is dealt with fairly fast. Numbers that go beyond it, like 30, show impossible runtimes. This is due to the fact that the number of steps of our trial method increases exponentially with n=|S|. By the way, in our program we built in a maximum of 30 elements in S. The subset problem is an example of an NP-complete problem. If you can find an algorithm which solves the problem in time polynomial in n, you will make history. See Lawler, Lenstra, Rinnooy Kan, Shmoys, The travelling salesman problem or the tekst from the vakantiecursus: P=NP?, which is in Dutch unfortunately and only viewable if you have a Postscript viewer. If you want a paper version of the text let me know.

Unfortunately, Netscape running under Solaris has rather bad behaviour in that update times for the graphics is very slow. So have patience when you work with this configuration. On a PC with Netscape the applet worked very well.