How to calculate the depth of an elimination tournament bracket

Posted on 2010-01-05
Last Modified: 2013-11-13
I am looking to write code to output elimination tournament brackets. I am at a step in the process where I am trying to figure out what teams should match up with each other to start the bracket (ie if 8 teams 1 plays 8, 4 plays 5, etc) and I think I've realised that to figure this out, I need to know how deep the tournament bracket goes (in the case of 8 teams it is 4 sections deep per below) I am trying to figure out the mathematics to determining this depth. I assume it must be similar to binary tree height, but I'm not sure how to do that?

I believe that in this problem statement the tree is complete, and I know the number of nodes and leaf nodes.

Tree example

1 -
     | ---
8 -       |
           | ---
4 -       |     |
     | ---      |
5 -             |
                 | ----
2 -             |
     | ---      |
7 -       |     |
           | ---
3 -       |
     | ---
6 -

Question by:dirknibleck
    LVL 15

    Accepted Solution

    If N is the number of teams, then tree depth would be log2(N). In case of 8 teams it's 3: quater-final, semi-final and final. Of course, for complete tree, the number of teams should be 2^N, where N is integer.
    LVL 11

    Expert Comment

    actually this is called a perfect binary tree: each node has exactly 2 children and all leaves have the same depth.
    the number of leaf nodes L (your number of teams) is
    L =  2^H
    where H is the height.

    So you can find the height by doing
    H = log2(L)

    LVL 11

    Expert Comment

    so... in C# you would do:
    int height = (int)Math.Log(numOfTeams, 2);

    of course this assumes you are indeed working with a "normal tournament". Meaning your number of team is a power of 2 = 2, 4, 8, 16, 32.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    Title # Comments Views Activity
    Two list de-cypher 6 81
    Independent Events 4 43
    Two Dice Roll Probabilities 3 32
    Triangles - computing angles 7 22
    Introduction This article discusses the Chain of Responsibility pattern, explaining What it is;Why it is; andHow it is At the end of this article, I hope you will be able to describe the use and benefits of Chain of Responsibility.  Backgrou…
    Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now