Imagine you have two groups, each of size
Now, this is often told as a story. One group is male, the other is female, and everyone gets married, hence the name the Stable Marriage Problem. This problem is solved by the Gale-Shapley algorithm, which can be simply described as follows:
- All the men propose to their top choice of women.
- The women become tentatively engaged to their top choice of the men who have proposed to them.
- All rejected men propose to their next choice, and the women again select whichever man they prefer, possibly rejecting the one they were already engaged to.
This process continues until all individuals are paired, which means that this algorithm guarantees stable matching and also has a
Here is a video describing the stable marriage problem:
{% method %} {% sample lang="ruby" %} import, lang:"ruby" {% sample lang="jl" %} import, lang:"julia" {% sample lang="py" %} import, lang:"python" {% sample lang="hs" %} import, lang:"haskell" {% sample lang="c" %} import, lang:"c" {% sample lang="cpp" %} import, lang:"cpp" {% sample lang="js" %} import, lang:"javascript" {% sample lang="cs" %}
import, lang:"csharp" {% sample lang="java" %} import, lang:"java" {% sample lang="php" %} import, lang:"php" {% sample lang="scala" %} import, lang:"scala" {% endmethod %}
<script> MathJax.Hub.Queue(["Typeset",MathJax.Hub]); </script>The code examples are licensed under the MIT license (found in LICENSE.md).
The text of this chapter was written by James Schloss and is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
After initial licensing (#560), the following pull requests have modified the text or graphics of this chapter:
- none