The stable marriage problem is an important problem in the field of economics, mathematics and in computer science. It helps in finding the stable matching between given two sets of equal and similar type dataset with given preferences. In the given set the preference of order of dataset is given. In this problem the mapping between given set is required to be done with the following condition:

An element in the matched set can set preferences to other matched set elements, matching can be done with other matched set too.

The elements can prefer other matching groups too.

Accordingly to the above conditions, it is required to find the mapping between the given set. The matching can be stable only when there is no better match group then formed match.

Given N men and N women, each person has ranked all the members of the opposite sex according to the order of preferences. It is required to marry the men and women in such a manner so that there are no two people of opposite sex who would both have no else partner than current partner.

Example-

Let there be two men M1 and M2 and two women W1 and W2

The preferences are as follows-

The M1 ‘s preference is –[W1,W2]

The M2’S preference is – [W1,W2]

The W1’S preference is -[M1,M2]

The W2’S preference is – [ M1,M2]

The most stable matching would be [M1,W1] and [M2,W2]

Algorithm Pseudo code-

For each women W= W1,W2, ——————Wn

S[W]= True if women is still single else false

T[W] = Temporary array or list for storing values of women who change state