Count pairs without counting twice

Start with n × n choices. Remove the n self-comparisons. There are now n(n−1) ordered pairs. A–B and B–A represent the same unordered pair for birthday equality, so divide by 2.
| n objects | Pairs |
|---|---|
| 1 | 0 |
| 2 | 1 |
| 5 | 10 |
| 9 | 36 |
| 30 | 435 |
| 100 | 4950 |
| 1000 | 499500 |
| 10000 | 49995000 |
Another way to see the formula is (n−1) + (n−2) + … + 1. For five cards this is 4 + 3 + 2 + 1 = 10. We also write this as “n choose 2”: choosing two different items without caring about their order.
Only halve reversed pairs when reversing the two items means the same test. “X is older than Y” has a direction; do not automatically treat every pair problem as symmetric. The pair totals here assume a complete scan without early stopping.
As n grows, the pair count grows roughly with n squared. Doubling a large n makes the work roughly four times as large. A fast computer still benefits from avoiding unnecessary work. Exact running time depends on the machine and what each comparison does; a fixed comparisons-per-second claim is only an illustration.
Try it yourself
Why is 30 × 30 ÷ 2 = 450 not the exact answer?
Show explained answer
It halves the self-comparisons too instead of removing them first. Use 30 × 29 ÷ 2 = 435.
Try it yourself
How many new comparisons does the final card make in the “later cards only” method?
Show explained answer
Zero. Its pair with every earlier card has already been checked.
Try it yourself
For 100 objects, is the exact pair count 10,000?
Show explained answer
No. That includes self-pairs and reversed pairs. The exact distinct unordered pair count is 100 × 99 ÷ 2 = 4,950.
