The Handshake Problem: Creating a Mathematical Solution
The handshake problem is very simple to explain. Basically, if you have a room full of people, how many handshakes are needed for each person to have shaken everybody else's hand exactly once?
For small groups, the solution is quite simple and can be counted fairly quickly, but what about 20 people? Or 50? Or 1000? In this article, we will look at how to work out the answers to these questions methodically and create a formula that can be used for any number of people.
For small groups, the solution is quite simple and can be counted fairly quickly, but what about 20 people? Or 50? Or 1000? In this article, we will look at how to work out the answers to these questions methodically and create a formula that can be used for any number of people.
Small groups
Let's start by looking at solutions for small groups of people.
The answer is obvious for a group of 2 people: only 1 handshake is needed.
For a group of 3 people, person 1 will shake the hands of person 2 and person 3. This leaves person 2 and 3 to shake hands with each other for a total of 3 handshakes.
For groups larger than 3, we will require a methodical way of counting to ensure we don't miss out or repeat any handshakes, but the math is still fairly simple.
The answer is obvious for a group of 2 people: only 1 handshake is needed.
For a group of 3 people, person 1 will shake the hands of person 2 and person 3. This leaves person 2 and 3 to shake hands with each other for a total of 3 handshakes.
For groups larger than 3, we will require a methodical way of counting to ensure we don't miss out or repeat any handshakes, but the math is still fairly simple.
Groups of 4 people
Suppose we have four people in a room, whom we shall call A, B, C and D. We can split this into separate steps to make counting easier.
- Person A shakes hands with each of the other people in turn—3 handshakes.
- Person B has now shaken hands with A but still needs to shake hands with C and D—2 more handshakes.
- Person C has now shaken hands with A and B but still needs to shake D's hand—1 more handshake.
- Person D has now shaken hands with everybody.
Larger groups
If you look closely at our calculation for the group of four, you can see a pattern that we can use to continue to work out the number of handshakes needed for different-sized groups. Suppose we have n people in a room.
- The first person shakes hands with everybody in the room except for himself. His total number of handshakes is, therefore, one lower than the total number of people.
- The second person has now shaken hands with the first person but still needs to shake hands with everybody else. The number of people left is, therefore, two lower than the total number of people in the room.
- The third person has now shaken hands with the first and second people. That means the remaining number of handshakes for him is three lower than the total number of people in the room.
- This continues with each person having one less handshake to make until we get to the penultimate person, who only has to shake hands with the last person.
The number of handshakes required for different sized groups
Number of people in the room |
Number of handshakes required |
2 |
1 |
3 |
3 |
4 |
6 |
5 |
10 |
6 |
15 |
7 |
21 |
8 |
28 |
Creating a formula for the handshake problem
Our method so far is great for fairly small groupings, but it will still take a while for larger groups. For this reason, we will create an algebraic formula to instantly calculate the number of handshakes required for any size group.
Suppose you have n people in a room. Using our logic from above:
This gives us the following formula:
Number of handshakes for a group of n people = (n - 1) + (n - 2) + (n - 3) + ... + 2 + 1.
This is still a little bit longer, but there is a quick and convenient way to simplify it. Consider what happens if we add the first and last terms together: (n - 1) + 1 = n.
If we do the same thing for the second and second to last terms, we get: (n - 2) + 2 = n.
In fact, if we do this all the way down, we get n each time. There are obviously n - 1 terms in our original series as we add numbers from 1 to n - 1. Therefore, by adding the terms above, we get n lots of n - 1. We've effectively added our entire sequence to itself here, so to get back to the sum we require, we need to halve this answer. This gives us a formula of:
Number of handshakes for a group of n people = n × (n - 1) / 2.
We can now use this formula to calculate the results for much larger groups.
Suppose you have n people in a room. Using our logic from above:
- Person 1 shakes n - 1 hands
- Person 2 shakes n - 2 hands
- Person 3 shakes n - 3 hands
- and so on until you get to the penultimate person shaking the one remaining hand.
This gives us the following formula:
Number of handshakes for a group of n people = (n - 1) + (n - 2) + (n - 3) + ... + 2 + 1.
This is still a little bit longer, but there is a quick and convenient way to simplify it. Consider what happens if we add the first and last terms together: (n - 1) + 1 = n.
If we do the same thing for the second and second to last terms, we get: (n - 2) + 2 = n.
In fact, if we do this all the way down, we get n each time. There are obviously n - 1 terms in our original series as we add numbers from 1 to n - 1. Therefore, by adding the terms above, we get n lots of n - 1. We've effectively added our entire sequence to itself here, so to get back to the sum we require, we need to halve this answer. This gives us a formula of:
Number of handshakes for a group of n people = n × (n - 1) / 2.
We can now use this formula to calculate the results for much larger groups.
Number of people in the room |
Number of handshakes required |
20 |
190 |
50 |
1225 |
100 |
4950 |
1000 |
499 500 |
An interesting aside: Triangular numbers
If you look at the number of handshakes required for each group, you can see that each time the group size increases by one, the increase in handshakes is one more than the previous increase had been. i.e.
- 2 people = 1
- 3 people = 1 + 2
- 4 people = 1 + 2 + 3
- 5 people = 1 + 2 + 3 + 4, and so on.
Comments
Don't forget to leave your comments below.