Bracket seeding in one line of code, and the sum that catches a bad draw

2026-12-02来源 dev.toEnglish
Bracket seeding in one line of code, and the sum that catches a bad draw

Ask someone to seed an 8-team bracket and they'll write 1 v 8, 2 v 7, 3 v 6, 4 v 5, top to bottom. The pairs are right. The order is wrong, and it puts the two best teams on course to meet in the semifinal.

In that layout the winner of 1 v 8 plays the winner of 2 v 7 next. If both favourites win, that is seed 1 against seed 2 with a round still to go, and the final is whoever is left.

The correct order down the page is 1 v 8, 4 v 5, 2 v 7, 3 v 6.

An 8-team seeded bracket
Seeds 1 and 2 sit in opposite halves; 1 to 4 sit in different quarters.

What seeding is for

Seeding places the teams so that the stronger a team is, the later it has to meet another strong one. Seeds 1 and 2 can only meet in the final. Seeds 1 to 4 can only meet from the semifinals on. Seeds 1 to 8 are kept apart until the quarterfinals, and so on down.

The top seed also gets the gentlest road the bracket has. In an 8-team bracket where every favourite wins, seed 1 plays seed 8, then seed 4, then seed 2. With 16 teams it is 16, 8, 4, 2. Each round it meets the weakest team that could still be there.

One line in a loop

Here is the function my bracket engine uses. It returns the seeds in the order they sit down the first round, and the flatMap line does all the work.

function seedOrder(size: number): number[] { let order = [1]; while (order.length < size) { const n = order.length * 2; order = order.flatMap((s) => [s, n + 1 - s]); } return order; } seedOrder(4); // [1, 4, 2, 3] seedOrder(8); // [1, 8, 4, 5, 2, 7, 3, 6] seedOrder(16); // [1, 16, 8, 9, 4, 13, 5, 12, 2, 15, 7, 10, 3, 14, 6, 11] 

Read the loop as a bracket growing backwards from the final. Start with one team, seed 1. To double the bracket, every seed already in it stays where it is and is handed an opponent: the seed that makes the pair add up to the new size plus one. In a bracket of 2 that gives 1 and 2. Double again and 1 gets 4, 2 gets 3. Double again and 1 gets 8, 4 gets 5, 2 gets 7, 3 gets 6.

Because every existing seed keeps its position, the structure from the smaller bracket survives inside the bigger one. That is why 1 and 2 stay in opposite halves at every size: they were placed in opposite halves when the bracket had two teams in it.

The sum that catches a bad draw

That loop gives you a check you can do on any printed bracket without understanding the rest.

In every first-round game of a full bracket, the two seed numbers add up to the bracket size plus one. In an 8-team bracket each pair makes 9. In a 16-team bracket each pair makes 17. For 32 it is 33.

If one pair doesn't, the bracket is seeded wrongly. If every pair does but 1 v 8 sits next to 2 v 7, the pairs are right and the order is wrong, which is the mistake at the top of this post.

The NCAA basketball committee builds its regions the same way. Its selection procedures place teams in four bracket groups per region: seeds 1, 16, 8, 9, then 4, 13, 5, 12, then 2, 15, 7, 10, then 3, 14, 6, 11. Compare that with seedOrder(16) above. It is the same list, cut into quarters.

What a random draw costs

If you skip seeding and draw names from a hat, the two best teams can only meet in the final when they happen to land in opposite halves. Fix the best team's position; of the other seats, half are in the far half of the bracket. So the chance is half the bracket size divided by one less than the bracket size.

Bar chart: chance that the two best teams land in opposite halves under a random draw
With 8 teams the top two are in the same half three draws in seven.

With 8 teams that is 4 in 7, about 57%. In the other 43% of draws they meet before the final, and one time in seven they meet in the very first round.

I ran this through a simulation with eight teams of fixed, unequal strength. Seeded, the final was 1 v 2 in 32.5% of tournaments. Drawn at random, 16.3%. The best team won the whole thing 40.5% of the time seeded and 35.9% drawn. For a decision that costs nothing, that is a large effect.

Seeding when you have no rankings

Most local events don't have a ranking list, and pretending to have one causes arguments.

If there are standings, a league table or last year's result, use them. If not, I'd do a split draw: agree on the two or four strongest teams, which is rarely controversial, give them the top seeds so they can't meet early, and shuffle everyone else. You get most of the benefit of seeding and nobody has to defend why they were ranked eleventh and not tenth.

A fully blind draw is the honest choice when nobody knows anything about the field, such as a first-time event with walk-up entries. Just say so before the draw.

One more adjustment many events make: if two teams from the same club would meet in round one, swap one of them with the neighbouring seed. It bends the rule slightly and stops people driving two hours to play their own training partners.

When the field isn't 8, 16 or 32

The same order still applies. With 11 teams you seed a 16-team bracket and leave seeds 12 to 16 empty. The teams drawn against an empty seat, seeds 1 to 5, move on without playing. Those are byes, and they go to the top seeds automatically because the top seeds are the ones paired with the highest numbers.

The seeding and byes guide on the site has the tables for every size up to 32. Every bracket there is seeded this way from the order you type the names in, best first, with a shuffle button for the blind draw; a 16-team bracket is a good one to try the add-up-to-17 check on. The seedOrder function is in the open-source engine at github.com/fancydirty/bracket-engine.

Written with AI assistance. The numbers were computed with the open-source engine linked above.

原文:https://www.a8q9.cn/en/article/bracket-seeding-in-one-line-of-code-and-the-sum-that-catches-a-bad-draw-75c216.html

相关文章