The Gale-Shapley Algorithm is a solution to the stable marriage problem, which involves matching two equal-sized groups of people (such as men and women) based on mutual preferences, ensuring that no two individuals would prefer to be matched together over their current partners; the algorithm works by having one group (traditionally proposers) sequentially propose to their most preferred choice who hasn't rejected them, while the receiving group accepts or rejects proposals based on whether the new offer is more favorable than their current engagement, resulting in a stable matching that is optimal for the proposers but pessimal for the receivers, with a computational complexity of O(n²).
Gale-Shapley Algorithm: Stable Matching with Step-by-Step Examples
Added:hello and welcome to this short educational video on the Gail shapley algorithm for stable matching the information in this video is drawn from the sources referenced in the information box below first off a short introduction the Gail shapley algorithm is a solution to the stable marriage problem and we must understand the problem to fully understand the solution in the stable marriage problem we want to create a set of n pairs using two sets of n people with one person from each set appearing in each pair each individual may only be paired once and as such the result will be a direct one-o-one mapping between the two sets of people the real complexity of this problem arises from Individual preferences each person has about who they would like to be paired with from the other set the challenge is to create a set of matchings for which there are no two people who prefer to be with each other than their current matchings respectively to help understand the problem and the algorithm which provides a solution to it here is an example we have two groups of people the males a b c d e and the females L M N O P we need to match all of them in a purely monogamous and due to the constraints of the problem heterosexual fashion for the purposes of this example and in keeping with the theme of the original problem this should be called marriage as you can see each person has a list next to their name containing all people from the other set in order of preference so for example person a would most likely be paired with person o followed by person M and so on it is important that this ranking is complete so that each person has a specified preference for each person in the opposite set note that it is not necessary for preferences to be reciprocated for example while person o is person E's Top Choice e is the least favorable match from O's perspective the gaay shapley algorithm itself is fairly simple to begin it is expected that each person has a strict ranking of members of the opposite group one of the two sets is chosen to make what we will call proposals while choosing either set will produce a stable matching the matching produced may be different but that is something we will look at later because in Western culture it is traditionally the males who propose to the females we will choose the male set to be the proposers the next part of the algorithm is a looping section one person from the proposing group in our case the males who is not already engaged will propose to his most preferable Choice who has not yet rejected him the female that has been proposed to must decide whether to accept or reject the proposal if she has not previously received an offer then she will accept if she has received a previous offer but the first offer is still more preferable then she will reject if she has received a previous offer but the new offer is more favorable then she will jilt or reject the previous proposer and accept the new one note that it does not matter in what order the males make their proposals as the stable matching will be the same this section will Loop until all people in the proposing group and thus all people in the other group are engaged at this point the pairs have been finalized and the people in the pairs are married here is an example of the algorithm working in practice firstly a proposes to his most preferable option o as o has no better options for the time being she accepts and a and o are engaged next B proposes to his most preferable option p and as she has not received any better offers she also accepts C proposes to M and she also accepts due to lack of any other offer D then proposes to P however P has already received a better offer from B and so she rejects D finally e proposes do o but as o has already received a better offer from a she turns him down at this point A B and C are already engaged and so do not attempt any more proposals D still has no fiance and so he proposes to his next most preferable Choice who has not rejected him m m prefers D to her previous offer from C and so she dumps C and is now engaged to d e proposes to L and as she has not previously received an offer she accepts c is now the only male who has yet to find a partner after being done by m he proposes to P then L then o but is turned down by all three as they have better options finally he proposes to n who accepts as she has not received any offers thus far all of the males are now engaged and as there is no need for any more proposals the current pairings are married with the final pairs being a o BP CN d m and e l all people have been successfully paired and while certain indiv idual did not get their preferred choices the matching is stable we know this because if a man preferred a woman to his current match he would already have proposed to her and she would have had to reject him meaning that she cannot prefer him to her current match as an interesting aside if we set the Woman's Group to be the proposers then we end up with a slightly different matching this matching is still stable but the trend in this example as in the majority of examples is that the matching is optimal from the proposer perspective notice that in this matching M and O got a more favorable outcome than previously while A and D ended up with a less favorable outcome we can see that each member of the proposing group can at most propose to each member of the other group only once as they cannot propose to those who have previously rejected them all proposals either end in provisional acceptance which means that no more proposals need to be made or rejection whether this is at the time or delayed until the better offer comes along if there are n members in each group the computational complexity of the algorithm is at most n s and in practice will often be less thank you for watching this video I hope you have found it useful and informative for any additional information regarding the Gail shapley algorithm please take the time to view the sources in the information box below thank you
Up Next

Game Theory Lecture: Clinching Auctions & TTC Algorithm
@timroughgardenlectures1861
5.2K views•2013-10-23

Introduction to Secure Multiparty Computation with Yehuda Lindell
@fhe_org
7.7K views•2021-02-04

HTTP Requests Explained: GET, POST, PUT, DELETE
@codecademy
103.1K views•2021-10-07

Enigma Machine Mechanics: WWII Encryption Explained
@JaredOwen
13.2M views•2021-12-11
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Computer Science






































![[Học thuật toán cùng TopAlgo] - Luồng cực đại và một số ứng dụng](https://i.ytimg.com/vi/HSI4JFHYpJk/hqdefault.jpg)
