-


> > > > Programming Assignments > Assignment 2 - Finding 3-free Sets

Objectives

Introduction

An arithmetic progression is an increasing sequence of integers with the same difference between adjacent integers in the sequence (mathematically, a sequence of the form $x, x+k, x+2k, \ldots, x+(n-1)k$ with $k > 0$). For example, $2, 6, 10$ is an arithmetic progression of length $3$ – the difference between 2 and 6 and between 6 and 10 is 4 (or take $x=2$ and $k=4$ and $n=3$ in the mathematical definition).

Sets that contain no subsets that form nontrivial (length 3 or more) arithmetic progressions (sometimes called nonaveraging sets) have an application to a particular problem in communication complexity, which in turn has applications to circuit design. For a given $n$, larger subsets of $\{0, \ldots, n-1\}$ with no arithmetic progressions generally yield better results for that application. For example, $\{0, 2, 3, 10, 12, 15, 16, 19\}$ has no arithmetic progressions, but neither does $\{0, 1, 5, 6, 8, 13, 14, 17, 19\}$ and the latter is likely more useful because it is larger. Note that there is no larger subset of $\{0, \ldots, 19\}$ that is free of arithmetic progressions. For example, no other integers in that range can be added to the second set above (2 because it would result the progression 0, 1, 2; 3 because of 0, 3, 5; 4 because of 4, 5, 6, etc.).

Assignment

Write a program called NoAP that constructs a set of unique integers that is free of nontrivial arithmetic progressions. The range of integers to use, integers to start with in the set, and the method by which to construct the set will be given as command-line arguments as follows.

The output of your program must be written to standard output with one line per method specifed on the command line (assuming no errors), and the output for the methods should be given in the order they are listed on the command line. Methods may be listed more than once and in that case the output will be repeated for each time they appear after the first (again, assuming no errors). Each line must be terminated by a newline character and must be in the form -method: k [x1, x2, x3, ..., xk] where -method is -greedy, -backward, -skip first step, or -opt, where k is the size of the set constructed, and the xi are the elements of the constructed set in increasing order.

Your program must perform the following error-checking (where each error message should end with a newline character):

If there is an error of the first two types then none of the requested methods should be used to construct a set and the error message is the only output. If there is an error in any of the $first$ and $step$ arguments then the preceding methods should be used and their output should be given before the error message for the offending -skip, and any subsequent methods are not used. In any case there should be no additional output beyond the first error message.

Do not treat the case where there is a nontrivial arithmetic progression among the must-include integers as an error; in that case display 0 [] for the constructed set for each requested method (as long as there are no other errors).

Aside from -opt, all methods for constructing the sets must run in $O(n^3)$ time.

Points for the optional -opt method will be added after any end-of-semester grade scaling. The -opt method will graded on increasing values of $n$ with a fixed time limit and the number of bonus points will depend in part on how many tests complete within the time limit.

If there are any other violations of the specifications for command-line arguments then your program must behave gracefully: it must not crash or go into an infinite loop.

Example

If your program is run as NoAP 15 2 4 8 -greedy -backward -skip 12 2 -opt then the output should be
-greedy: 5 [2, 4, 8, 9, 11]
-backward: 6 [2, 4, 8, 10, 11, 13]
-skip 12 2: 4 [2, 4, 8, 10]
-opt: 6 [2, 4, 8, 10, 11, 13]
because

You can check that your results for -opt are as large as they can be by referring to the Online Encylopedia Of Integer Sequences entry A003002, which gives the size of the largest set up to $n=77$ and some examples (shifted over by one since they list subsets of $\{1, \ldots, n\}$ instead of $\{0, \ldots, n-1\}$); see Finding large 3-free sets I: the small n case in JCSS vol 74:4 for the size of the largest possible set up to $n=187$ (without examples but with descriptions of some improvements to the standard backtracking algorithm). You will also have to make sure your output is the lexicographically first set of the given size (all of the examples from OIS I checked were the lexicographically first ones).


Valid HTML 4.01 Transitional