Number of matches required to find a winner


Tournaments can be of various types- single elimination, double elimination, league etc., Suppose you are an organizer and you want to know about how many matches needs to conducted in order to conduct the tournament according to the rules of the game.

In this article, we will discuss about different ways to find the number of matches required to find a winner using C++.

Understanding the Problem

In a single elimination tournament, we have series of matches in which each team or player gets to compete with the other one. In each match, there are two teams or players. The losing one gets eliminated. After each round, teams get eliminated until a winner is declared.

  • In double elimination tournament, we have two categories. First, all the teams with each other once. The losers don’t get eliminated instead; they are moved to the losers’ category in which they compete with each other. Similarly, matches happen between the winners’ category.

  • At the end, there is grand finale in which the winner of the winners’ category and the winner of the losers’ category compete. If the winner of winners’ category wins, then, it becomes the ultimate winner. While if the winner of the losers’ category wins, the match is held once again to decide the winner.

  • In League tournament, each participant competes against all the other participants once. The participant who has the maximum number of wins becomes the ultimate winner.

We have to find the number of matches required to find the winner for these types of tournaments.

Input Output Scenarios

Suppose you are given the number of teams or players participating in a tournament. The output gives the number of matches required to find the winner.

In case of single elimination
Input: N = 8
Output: 7
In case of double elimination
Input: N = 8
Output: 14
In case of league tournament
Input: N = 8
Output: 14

Single Elimination Tournament

We have N number of teams or players. If N is even then, N/2 number of matches will be needed for each round and N/2 number of players or teams will move to the next. If N is odd then, N/2 matches will be needed for the first-round while N/2 and one more team will move to the next.

Let’s take an example with 14 teams participating in the tournament. So, the rounds of matches will be as follows −

  • For first round, 14 teams compete with each other in 7 matches. 7 teams move to the next.

  • For second round, 7 teams compete in 3 matches. 4 teams move to next.

  • For the third round, 4 teams compete in 2 matches. 2 teams move forward.

  • 2 teams compete in the final match to get the winner.

Total number of matches = 7 + 3 + 2 + 1 = 13 which is (N – 1).

Hence, number of matches required to find the winner in a single elimination tournament is (N – 1)

Example

Let us see an example −

#include <iostream>
using namespace std;
int numOfMatches(int N){
   int result = (N - 1);
   return result;
}
int main(){
   int N = 16;
   std::cout<< "Number of matches to find the winner are: " <<
   numOfMatches(N);
   return 0;
}

Output

Number of matches to find the winner are: 15

Double Elimination Tournament

For double elimination tournament, matches in the winner category will be same as that in single elimination tournament. For the losers’ category, we have (N – 2) matches. Number of matches in the finale can be 1 or 2 depending on which category wins the finale match.

Number of matches
   = number of matches for winner category
   + number of matches for loser category
   + number of matches in grand finale
   = (N – 1) + (N – 2) + 1 (or 2)

Example

#include <iostream>
using namespace std;
int main(){
   int N = 8;
   // Number of Matches for the winners’ category
   int result1 = (N - 1);
   // Number of Matches for the losers’ category
   int result2 = (N - 2);
   int num1 = result1 + result2 + 1;
   int num2 = result1 + result2 + 2;
   std::cout<< "Number of matches" << std::endl;
   std::cout<< "When winner is from winners' category are: " << num1<<
   std::endl;
   std::cout<< "When winner is from losers' category are: " << num2 <<
   std::endl;
   return 0;
}

Output

Number of matches
When winner is from winners' category are: 14
When winner is from losers' category are: 15

League Tournament

For each team, there will be (N - 1) matches. Also, each team needs to compete every other player or team. Hence, number of matches required will be (N * (N - 1)). However, in each match two of the teams are involved and the above formula makes up double the number of matches needed.

Therefore, the final formula for find the number of matches comes out to be −

(N * (N - 1)) / 2

Example

Following is an example to calculate the number of matches required to find a winner −

#include <iostream>
using namespace std;
int numOfMatches(int N){
   int result = (N * (N - 1)) / 2;
   return result;
}
int main(){
   int N = 7;
   std::cout<< "Number of matches to find the winner are: " << numOfMatches(N);
   return 0;
}

Output

Number of matches to find the winner are: 21

Conclusion

We have discussed ways for finding the number of matches required to find the winner in case of single elimination, double elimination and league tournaments. We have used different formulae for these kinds of tournament.

Updated on: 05-Jan-2024

27 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements