Assuming Transitivity holds i.e if A > B and B > C then A > C, then solving this is like sorting an array of 5 elements.
Applying DivideAndConquer algorithm.
Let the fencers be A,B,C,D,E.
Now lets follow the below steps:
- Pick anyone. He fights with everyone undecided in his group to divide the group into two: one better than him and other worse than him.
In the worst case, it would be:
- A fights with B,C,D,E (All belong to the better group with none in the other group: Group 1 {} Group 2 {B,C,D,E}) [Fights = 4]
- B Fights with C,D,E (All belong to the better group with none in the other group: Group 1 {} Group 2 {C,D,E}) [Fights = 3]
- C Fights with D,E (All belong to the better group with none in the other group: Group 1 {} Group 2 {D,E}) [Fights = 2]
- D Fights with E (E wins: Group 1 {} Group 2 {E}) [Fights = 1]
Skill sequence: A < B < C < D < E
Total fight (Worst case) : 4 + 3 + 2 + 1 = 10.
In the best case, it would be
- A fights with B,C,D,E (Groups equally split: Group 1 {B,C} Group 2 {D,E}) [Fights 4]
- B Fights with C (B Wins: Group 1 {C} Group 2 {B}) [Fights 1]
- D Fights with E (E wins: Group 1 {D} Group 2 {E}) [Fights 1]
Skill sequence: B > C > A > E > D
Total fight (Best case) : 4 + 1 + 1 = 6
In general, for 'x' fencers, in the worst case (x-1)*x/2 fights needs to be fought.