Nepedia
Back to Discover
Advanced Reader
🔢

Stable roommates problem

math Maturity 7-9 Next article →

The stable roommates problem (SRP) is a challenge found in mathematics, economics, and computer science. It specifically belongs to the fields of combinatorial game theory and algorithms. The goal is to find a stable matching for a set of an even number of people. A matching is a way to separate a group into disjoint pairs, which we call roommates. A matching is considered stable if there are no two people who are not currently roommates but both prefer each other over their assigned partners. If such a pair exists, they are called a blocking pair because they could disrupt the current arrangement.

This problem is distinct from the more famous stable marriage problem. In the stable marriage problem, participants only match between two specific classes, such as men and women. However, the stable roommates problem allows any participant to match with any other participant in the set. This flexibility makes the mathematics more complex. Because anyone can match with anyone, a stable matching may fail to exist entirely. For example, if four people have specific, conflicting preferences, any pairing will result in a blocking pair. In such a scenario, the participants' rankings make it impossible to satisfy everyone without someone wanting to switch.

To solve this, mathematicians use Irving's algorithm. This efficient algorithm can determine if a stable matching exists and find it if it does. The algorithm has a computational complexity of O(n^2) when using proper data structures. It works by manipulating preference lists and identifying specific patterns called rotations. The process is divided into two distinct stages: Phase 1 and Phase 2. Phase 1 focuses on a series of proposals, while Phase 2 focuses on reducing the remaining options through elimination.

In Phase 1, participants propose to others in a manner similar to the Gale-Shapley algorithm. Each participant has a preference list, which is an ordered set of all other members. Participants propose to people on their list one by one. If a participant receives a proposal from someone they prefer more than their current proposer, they reject the current one. This continues until everyone holds a proposal or someone is rejected by everyone. If someone is rejected by all others, no stable matching is possible. If Phase 1 succeeds, it results in a Phase 1 table, which is a reduced set of preference lists.

Phase 2 begins if the Phase 1 table still contains multiple options for any participant. This stage relies on the concept of a rotation. A rotation is a specific sequence of pairs (x, y) where each person is linked to someone on their reduced preference list. Specifically, for a sequence of participants, each person's first choice is linked to the next person's second choice in a repeating cycle. If a stable table has a list with at least two individuals, a rotation always exists. The algorithm finds this rotation and eliminates it by having certain participants reject others.

Eliminating a rotation involves removing certain names from preference lists to restore the properties of a stable table. As these names are removed, the algorithm checks if any list becomes empty. If a list becomes empty, the algorithm concludes that no stable matching exists. If the elimination process continues until every person's reduced list contains exactly one individual, the algorithm has found a stable matching. This matching is the set of pairs where both individuals are the only ones left on each other's lists.

This mathematical concept is implemented in many modern software packages. For instance, Python includes an implementation within its matching library. Java offers a constraint programming model to find all stable matchings, even with incomplete lists. The R programming language uses the matchingMarkets package for similar tasks. There is also a web-based tool called Dyad Finder that uses JavaScript to solve the problem. Additionally, the United States Naval Research Laboratory provides a version for MATLAB called assignStableRoommates. These tools allow researchers to apply the theory to complex, real-world matching systems.

669 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.