2. Text problem 6.4.
3. Text problem 6.8.
4. Text problem 6.22.
5. A classic ice-breaking exercise is for a group of n people to form a circle and then arbitrarily join hands with one another. This forms a "human knot" since the players' arms are most likely intertwined. The goal is then to unwind the knot to form a circle of players with no arms crossed.
We now adapt this game to a more general and more abstract setting where the physical constraints of the problem are gone. Suppose we represent the initial knot with a 2-regular graph inscribed in a circle (ie, we have a graph with n vertices with exactly two edges touching each vertex). Initially, some edges may cross other edges and this is undesirable. This is the "knot" we wish to unwind.
A "move" involves moving any vertex to a new position on the circle, keeping its edges intact. Our goal is to make the fewest possible moves such that we obtain an n-sided polygon with no edge-crossings remaining.
For example, here is a knot on 4 vertices inscribed in a circle, but two edges cross each other. By moving vertex 4 down to the position between 2 and 3, a graph without edge-crossings emerges. This was achieved in a single move, which is clearly optimal in this case.
When n is larger, things may not be quite as clear. Below we see a knot on 6 vertices. We might consider moving vertex 4 between 5 and 6, then vertex 5 between 1 and 2, and finally vertex 6 between 3 and 4; this wins in 3 moves.
But clearly we can solve the same knot in only two moves:
Give an efficient algorithm to solve this problem. You do not need to code your solution. Although this is the chapter on Dynamic Programming, you don't actually need DP here; but use one of our DP algorithms as a subroutine to solve this problem. Your solution should use O(n2) time.