McGill University:
School of Computer Science
Winter 1999 Projects for 308-251B

DATA STRUCTURES AND ALGORITHMS

Project #59: Tournament Trees and Tennis

Last update: April 3, 1999


Project #59

Explore the following idea: construct a tournament tree by mimicking a tennis tournament. The largest element (best tennis player) ends up at the top. Can you translate this into a data structure, and can you insure that insert and deletemin can be carried out in O(log n) worst-case time? Do not assume that n is a power of 2. Illustrate your work with one or more drawings.


The Tennis Tournament

    A tennis tournament is formed in the following way:
  1. Competitors are randomly chosen and paired off. If there are not enough players to make a power of 2, "byes" are also entered into the draw (random space) until there are. These "byes" or empty spots, may be paired up with players, thus giving these lucky players the first round off, and an automatic advancement to the second round.
  2. Once all players are paired off, these pairs form the first round. The first round plays, and the winners advance to the next round. The losers drop out.
  3. The winners of the first round are then paired off and form the second round. They play. The winner advances. The loser drops out.
  4. This repeats, with the winners of the last round pairing off and forming the next round, until there is only the tournament winner remaining.

Here is an example of the basic tennis tournament with 12 players: Unseeded tennis tournament tree

Now what makes tennis really interesting is the concept of seeding. Since the first round is chosen by random, it is possible for the two best players to play each other in the first round, thus knocking one out right away. This is fustrating for the loser, as he or she does not get to play the rest of the tournament, and it tends to make the tournament a bit anti-climatic as the remaining player is now the best player in the tournament, and proceeds to clean house for the remainder of the tournament.

To prevent this, seeding was introduced. The top players, usually the top 4 to 16 depending on the number of competitors, are placed in specific positions in the first round. The top two players are put as far away from each other as possible, i.e. the edge of the tree. What this accomplishes is to make it so that the only place that the top two players will possibly meet, is in the finals.

One final little detail. Byes are usually given to the top seeded competitors. This is to give them a break as they will be playing much more difficult games against the better competitors. Why waste energy on the little people since the outcome is known.

Here is an example of a seeded tournament with 12 competitors: A seeded tennis tournament
The seeded player are in red.


The Tournament Tree Data Structure

So how does one turn a tennis tournament into a data structure? And what will it buy us?

We can turn a tennis tournament into a data structure called (surprise, surprise!) a tournament tree. You build a tournament tree in a way similar to how you build a tennis tournament. Take all the elements that you have and put them on the bottom of the tree. Pair up the elements. For each pair, choose a winner and make the winner the parent of pair. This creates a second layer of element, for which you repeat the process. Keep repeating until you have a complete binary tree.

Of course this is only really useful if you have a systematic way of choosing the winner. By having each node have a key, you can create a minimum tournament tree, or a maximum tournament tree, by choosing the respective element of each pair as the winner.

Now you may have problems if you do not have 2^N nodes for some integer N. You cannot make a complete binary tree without 2^N nodes at the lowest level. So we will solve the problem in the same way as with a tennis tournament. We fill up the rest of the space with blanks. The blanks will always lose when they come up against a real node. So for a minimum tournament tree, the blanks would be infinity, and for the maximum tournament tree, the blanks would be negative infinity.

Here is an example of a minimum tournament tree:
A tournament tree
Notice that nodes are repeated.

Tournament trees have the following operations on them:

This takes O(n) comparisons

This takes O(lg n) comparisons.

An example of REPLAY
Replaying a tree

This takes O(lg n) comparisons for the REPLAY. Finding the path is trivial.

An example of DELETEMIN
Deleting the minimum of a tournament tree

These are the basic operations on tournament trees. However, one can make a priority queue by adding an operaiton INSERT. This however is a bit more difficult.

An example of insert over the 2^N barrier Inserting over the 2^N barrier with an exogenous tournamen tree

With DELETEMIN, sorting is again trivial. Just run repeated DELETEMINs until all the elements are gone. The order that the elements come out in is the sorted order. This takes O(N lg N) comparisons.


Tennis Tournaments and Tournament Trees

So how can you further mimick a tennis tournament with tournament trees? Well, there really is only one thing left, and that is seeding.

To seed, you just place the top(smallest) elements at specific positions in the bottom of the tree. This again is made much easier with an exogenous data structure. Actually, seeding does very little for our data structure as there is not way for the second smallest element to lose to anyone except the smallest element.

That's it. Tournament trees are a data structure that arise from a real life object. They can be used to implement the priority queue ADT. They also show how exogenous and endogenous data sturctures can have an effect on running time.


Links to related material

Information on tournament trees on the web were quite scarce. Heck, information on how to build a tennis tournament was quite scarce to non-existant on the web. Here are the few web sites that I found.
Sorting algorithms

There is Tournament Sort towards the bottom

Course notes from CS251 1997 on Priority Queues

Explains the tournament tree quite well.

rec.sports.tennis FAQ miscellaneous

Section 6.7 is about professional tournament seeding.


References

Searching for algorithms in books is a bit difficult and time consuming. I didn't find any books with tournament trees in them. I did need the following books to fill in some of the gaps in my knowledge, like not knowing a thing about tennis tournaments

  1. McEnroe, Patrick, et al. Tennis for Dummies. IDG Books Worldwide, 1998.
    Explains enough about tennis so you can play it and watch it.
  2. Cormen, Thomas H., Charles E. Leiserson, and Ronald L. Rivest. Introduction to Algorithms. The MIT Press, 1989.
    For information on priority queues.


Web page creators

This web page was created by Marshal Wong ([email protected]).


Last updated March 23, 1999 by Marshal Wong. Copyright © 1999, Marshal Wong.