Nepedia
Back to Discover
Fluent Reader
🔢

Stable roommates problem

math Maturity 7-9 Next article →

Imagine you have a group of people who need to find roommates. Each person makes a list of everyone else. They rank these people from their favorite to their least favorite. A matching is a set of pairs made from this group. We want to find a matching that is stable. A matching is stable if no two people want to switch partners. This happens if no two people both prefer each other over their current roommates. If they do want to switch, they are called a blocking pair.

This problem is different from the stable marriage problem. In the marriage problem, people match between two different groups. In the stable roommates problem, any person can match with anyone else. This makes the math a bit more tricky. Sometimes, a stable matching might not even exist. For example, if four people have very specific rankings, they might always want to swap. In those cases, no matter how you pair them, someone will be unhappy.

To solve this, mathematicians use Irving's algorithm. This is a way to find a stable match or prove one is impossible. The process happens in two main parts. In Phase 1, participants propose to people on their lists. If someone receives a better proposal, they reject their current one. This continues until everyone holds a proposal or someone is rejected by everyone. This phase creates a special list called a Phase 1 table.

Phase 2 of the algorithm deals with something called rotations. A rotation is a specific sequence of people and their choices. If the Phase 1 table still has many choices for each person, the algorithm looks for these rotations. It identifies a rotation and then eliminates it from the table. This narrows down the choices further. If a list becomes empty during this part, then no stable matching exists. If every person is left with only one choice, the algorithm has found a stable matching.

Computer scientists use this math in many different ways. You can find Irving's algorithm in software like Python and Java. It is also used in the R matchingMarkets package. Some people even use a website called Dyad Finder to run the math. The United States Naval Research Laboratory has a version for MATLAB too. These tools help people solve hard matching jobs using math.

388 words

Where will your curiosity go next?

Keep exploring at your chosen reading level.

More to explore

What is Nepedia?

A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.