Solution to The Carpenter Ruler Problem

Graders: Wenqing Deng, Yangang Li, Anuradha Sethuraman , Jun Wang.

The Problem:


This problem deals with the Carpenter's Ruler.

Solution to part A:

Algorithm:

  1. Run a linear algorithm to find the maximum link(or one of the maximum links) of the ruler, call it link AB.

  2. Establish a coordinate with positive direction to the right hand side and with a zero point Z.

  3. Place the maximum link AB onto the coordinate; align point A with point Z and make the link toward the positive direction.

  4. Consider the remaining links one at a time and in order, beginning with end point A and end point B respectively. For each link, if its starting point is in the range [A,B] inclusive, then fold it to the positive direction; otherwise, fold it to the negative direction. Do the same thing until all the remaining links are folded.

It is easy to see that the algorithm does the folding within the range [0,2m] by noting that if the link is folded to the right, then its starting point (i.e. the point connected to already placed link that it connects to) is located in the range [0,m], hence once placed, the ending point of that link is located at a point no greater than 2m, since m is the maximum link length. Similarly if the link is folded to the left, then its starting point is lcoated in (m,2m], hence once placed its ending point is no less than zero.

Complexity: The running time is clearly O(n) --- that is, linear.

Solution to part B:

To prove the above (part a) bound is optimal, we must find at least one ruler with maximum link length of M, such that, given any e(epsilon), we cannot fold the ruler in less than 2M-e.

In fact we can construct such a ruler. Consider a ruler that consists of 2*ceiling(m/e) links. We build the ruler in a particular way such that it looks like:

M , M-e , M , M-e , M , M-e , ...

That is, every other link (say, even numbered links) is of length M, and every other link (say, odd numbered links) is of length M-e.

We claim that an optimal folding is 2M-e.

Proof: