An efficient algorithm to pair chess players in a team tournament

766 Views Asked by At

I found this question on a website.

Your team is playing a chess tournament against a visiting team. Your opponents have arrived with a team of $M$ players, numbered $1,2,\dots,M$. You have $N$ players, numbered $1,2,\dots,N$ from which to choose your team, where $N \ge M$.

Each of the $M$ players from the visiting team must be paired up with one of your $N$ players. The tournament rules insist that the pairings must respect the order that has been fixed for both teams. That is, when you pick players $i_1, i_2,\dots, i_M$, to play against opponents numbered $1,2,\dots,M$, it must be the case that $i_1<i_2< \dots <i_M$, in terms of the order $1,2,\dots,N$ in which your players are listed.

You want to ensure a good fight, so you plan to pick your team so that the teams are as evenly balanced as possible. Each player $j$ on your team has a numerical score $YS(j)$ that represents his or her playing ability. Likewise, each player $i$ in the opponent team has a playing ability indicated by a numerical score $OS(i)$. The difference in strength between a player $ij$ from your team and his or her opponent $j$ on the visiting team is the absolute value $|YS(i_j) - OS(j)|$. The imbalance of a pairing is the sum of these differences across all $M$ match-ups in the pairing. Your aim is to minimize this imbalance.

The solution I had in mind, was to sort the two arrays, and find the least number of adjacent switches till there was no $i>i+1$ index.

However this would not work when one sorted array is:

[1,2,3,4,...,9]

while the other is:

[7,8,9]
1

There are 1 best solutions below

0
On

How about sort the two arrays, then match each of the opposing players with the closest of your players in rating. If none of the opposing players are matched more than once, you are done. If any of the opposing players are double booked, compare the effect of matching your higher ranked player with the next opponent up the line (continuing to push up if necessary) with the effect of matching your lower ranked player with the next opponent down the line.