Algorithms – Tournament Bracket Method to Separate Teammates

algorithmsbinary treedata structuressorting

I am using a proper binary tree to simulate a tournament bracket. It's preferred any competitors in the bracket that are teammates don't meet each other until the later rounds. What is an efficient method in which I can ensure that teammates in the bracket have as much distance as possible from each other? Are there any other data structures besides a tree that would be better for this purpose?

EDIT: There can be more than 2 teams represented in a bracket and there is no requirement to have an equal number of people from each team in a bracket. I intend to use this for individual sports where a person still has an affiliation with a team and we want to delay teammates facing each other until as late as possible.

Best Answer

Just sort the players by team and number them starting from 0, so e.g.

0(000)  T1a (team 1 player a)
1(001)  T1b
2(010)  T1c
3(011)  T2a
4(100)  T2b
5(101)  T3a
6(110)  T3b
7(111)  T3c

Then reverse the bits in each number to fill out your bracket sheet

0(000)  T1a\______
1(001)  T2b/      \_______
2(010)  T1c\______/       \
3(011)  T3b/               \________
4(100)  T1b\______         /
5(101)  T3a/      \_______/
6(110)  T2a\______/
7(111)  T3c/