# Algorithm — Stable matching problem implementation using c++

The concept , pseudocode and implementation about stable matching problem

#### Concept

From wikipedia :

*In **mathematics**, **economics**, and **computer science**, the **stable marriage problem** (also **stable matching problem** or **SMP**) is the problem of finding a stable matching between two equally sized sets of elements given an ordering of preferences for each element. A **matching** is a mapping from the elements of one set to the elements of the other set. A matching is not stable if:*

*There is an element A of the first matched set which prefers some given element B of the second matched set over the element to which A is already matched, and**B*also prefers*A*over the element to which*B*is already matched.

*In other words, a matching is stable when there does not exist any match (A, B) by which both A and B would be individually better off than they are with the element to which they are currently matched.*

*The stable marriage problem has been stated as follows:*

*Given n men and n women, where each person has ranked all members of the opposite sex in order of preference,**marry**the men and women together such that there are no two people of opposite sex who would both rather have each other than their current partners. When there are no such pairs of people, the set of marriages is deemed stable.*

#### Pseudocode(From **Gale–Shapley algorithm**)

#### Implementation(Using cpp)

Special thanks to the submission of the code about stable matching problem.

When I implement the code not having a good condition which leads to poor brain functioning. So thanks again to the submission solution helps me a lot in clarify the problem.

#### Reference

**Stable marriage problem - Wikipedia**

*In mathematics, economics, and computer science, the stable marriage problem (also stable matching problem or SMP) is…*en.wikipedia.org

**Contest Page | CodeChef**

*CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and…*www.codechef.com

**Solution: 13142595 | CodeChef**

*Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our…*www.codechef.com

Givennmen andnwomen, where each person has ranked all members of the opposite sex in order of preference,marrythe men and women together such that there are no two people of opposite sex who would both rather have each other than their current partners. When there are no such pairs of people, the set of marriages is deemed stable.