I have $n$ people seated around a circular table, initially in arbitrary order. At each step, I choose two people and switch their seats. What is the minimum number of steps required such that every person has sat either to the right or to the left of everyone else?

To be specific, we consider two different cases:

- You can only switch people who are sitting next to each other.
- You can switch any two people, no matter where they are on the table.

The small cases are relatively simple: if we denote the answer in case 1 and 2 for a given value of $n$ as $f(n)$ and $g(n)$ respectively, then we have $f(x)=g(x)=0$ for $x=1, 2, 3$, $f(4)=g(4)=1$. I'm not sure how I would generalize to larger values, though.

(I initially claimed that $f(5)=g(5)=2$, but corrected it based on @Ryan's comment).

*If you're interested, this question came up in a conversation with my friends when we were trying to figure out the best way for a large party of people during dinner to all get to know each other.*

**Edit:** The table below compares the current best known value for case 2, $g(n)$, to the theoretical lower bound $\lceil{\frac{1}{8}n(n-3)}\rceil$ for a range of values of $n$. Solutions up to $n=14$ are known to be optimal, in large part due to the work of Andrew Szymczak and PeterKošinár.

\begin{array} {|r|r|l|} \hline n & \text{Best known value of g(n)} & \left\lceil{\frac{1}{8}n(n-3)}\right\rceil & \text{Comments}\\ \hline 4 & 1 & 1 & \\ \hline 5 & 3 & 2 & \\ \hline 6 & 4 & 3 & \\ \hline 7 & 4 & 4 & \\ \hline 8 & 6 & 5 & \\ \hline 9 & 8 & 7 & \\ \hline 10 & 10 & 9 & \\ \hline 11 & 12 & 11 & \\ \hline 12 & 14 & 14 & \\ \hline 13 & 17 & 17 & \\ \hline 14 & 20 & 20 & \\ \hline 15 & 24 & 23 & \\ \hline 16 & 28 & 26 & \\ \hline 17 & 32 & 30 & \\ \hline 18 & 37 & 34 & \\ \hline 20 & 47 & 43 & \text{Loose upper bound}\\ \hline 25 & 77 & 69 & \text{Loose upper bound}\\ \hline 30 & 114 & 102 & \text{Loose upper bound}\\ \hline \end{array}

The moves corresponding to the current best value are found below. Each ordered pair $(i, j)$ indicates that we switch the people in **seats** $(i, j)$ with each other, with the seats being labeled from $1 \ldots n$ consecutively around the table.

```
4 - ((2,1))
5 - ((2,5),(1,5),(1,3))
6 - ((5,3),(1,5),(2,5),(3,6))
7 - ((4,7),(3,7),(1,5),(2,5))
8 - ((1,2),(4,7),(1,5),(3,7),(1,6),(2,5)) (h.t. PeterKošinár)
9 - ((3,8),(1,4),(6,9),(4,8),(1,6),(5,8),(2,8),(2,9))
10 - ((3,8),(4,8),(7,10),(1,7),(3,6),(1,5),(2,9),(3,7),(1,4),(3,9))
11 - ((4,8),(2,9),(5,8),(1,7),(3,9),(7,11),(5,10),(1,4),(5,9),(2,7),(2,6),(5,10))
12 - ((1,2),(5,10),(1,6),(4,10),(1,7),(8,11),(4,12),(3,12),(1,9),(1,5),(7,11) (1,8),(5,10),(2,6))
13 - ((1,2),(1,7),(3,9),(6,12),(8,11),(8,12),(1,11),(4,12),(9,12),(6,10),(7,10),(1,6),(2,8),(5,9),(3,8),(8,12),(9,12))
14 - ((1,4),(1,5),(1,8),(1,12),(4,11),(4,12),(9,13),(1,12),(9,12),(6,10),(6,9),(1,9),(4,7),(4,13),(3,13),(3,10),(2,13),(2,7),(3,13),(4,12))
15 - ((0,3),(0,10),(4,7),(2,8),(1,8),(5,9),(3,14),(5,13),(2,11),(4,9),(5,14),(4,12),(2,6),(7,14),(0,3),(2,9),(6,10),(8,11),(0,12),(0,4),(0,7),(3,7),(3,10),(2,13))
16 - ((10,14),(10,13),(0,10),(5,9),(5,8),(2,12),(2,5),(7,12),(2,12),(3,14),(5,11),(0,5),(4,14),(4,7),(3,11),(3,10),(0,8),(0,9),(0,6),(3,6),(1,14),(11,15),(1,5),(6,14),(3,11),(11,14),(0,12),(1,4))
17 - ((9,15),(5,13),(13,16),(0,13),(2,10),(10,16),(5,16),(5,13),(2,6),(2,10),(10,16),(7,10),(4,15),(1,8),(4,9),(5,12),(4,10),(3,13),(5,14),(1,4),(5,15),(1,6),(5,12),(8,12),(7,12),(4,12),(0,12),(8,11),(8,14),(7,16),(2,3),(1,8))
18 - ((4,7),(4,14),(6,10),(7,13),(4,7),(8,16),(8,13),(7,13),(3,8),(0,8),(4,8),(6,16),(1,12),(1,5),(5,11),(0,5),(14,17),(1,13),(8,13),(3,13),(0,4),(11,16),(2,10),(11,17),(9,15),(10,15),(1,9),(2,13),(1,4),(5,12),(6,14),(7,16),(13,17),(0,15),(1,15),(6,10),(5,15))
# Note that some solutions are zero-indexed and some are one-indexed.
```

The code I used to generate my the results can be found on Github. Unless otherwise specified, the switches above were found by my code, using a randomized greedy approach. As demonstrated by PeterKošinár, since the total number of possibilities is large, this approach may not find the best result even after many trials.