Simplify Your Workflow: Search MiniWebtool.
Add Extension
Related Tools
Karnaugh Map (K-Map) SolverLinear Programming SolverPigeonhole Principle CalculatorTopological Sort CalculatorTraveling Salesman Solver (TSP)
Home Page > Math > Advanced Math Operations > Stable Marriage Problem Solver

Stable Marriage Problem Solver

Solve the stable marriage / stable matching problem using the Gale-Shapley algorithm. Paste ranked preference lists for two equally-sized groups and get the guaranteed-stable pairing, with an animated proposal-by-proposal trace, satisfaction statistics, blocking-pair verification, and an interactive bipartite visualization.

Stable Marriage Problem Solver
A
One line per member: Name: Pref1, Pref2, ... โ€” list every Group B member in preference order.
B
Same format. Each Group B member ranks all Group A members.
In Gale-Shapley, the proposing side gets their best possible stable partner; the receiving side gets their worst.

Embed Stable Marriage Problem Solver Widget

About Stable Marriage Problem Solver

The Stable Marriage Problem Solver is an interactive implementation of the Gale-Shapley deferred-acceptance algorithm, the 1962 matching algorithm that David Gale and Lloyd Shapley proved always produces a stable pairing between two equally-sized groups given each member's full ranking of the other side. This tool takes your preference lists, runs the algorithm step by step, and shows the result as a stable matching, an animated bipartite visualization, preference heatmaps, and a verified proof that no blocking pair exists.

What Is the Stable Marriage Problem?

Given two disjoint sets of equal size โ€” say n men and n women, or n applicants and n positions โ€” and a complete preference list from every member ranking every member of the other side, a matching is a one-to-one pairing between the two sets. The matching is called stable if no pair (a, b) outside the matching would both rather be together than stay with their assigned partners.

Formally, a matching M is stable if there is no blocking pair โ€” a pair (a, b) with a matched to b' and b matched to a' such that:

a prefers b to b' AND b prefers a to a'

If both conditions hold, both a and b would abandon their current partners, which destabilises the matching. A stable matching is one where no such pair exists.

The Gale-Shapley Algorithm

Gale and Shapley proved โ€” constructively โ€” that a stable matching always exists for any set of preferences, and they gave an efficient algorithm to find one. The algorithm runs in rounds:

  1. Every unengaged proposer proposes to the highest-ranked receiver on their list who has not yet rejected them.
  2. Each receiver who got one or more proposals picks the one they prefer most (compared against any current tentative fiancรฉ) and tentatively accepts; everyone else is rejected.
  3. Rejected proposers become free again and move on to their next choice in the following round.
  4. The algorithm terminates when every proposer is engaged โ€” which is guaranteed to happen in at most nยฒ proposals.
Time complexity: O(nยฒ) Space complexity: O(nยฒ) Proposals before termination: at most nยฒ

Key Theoretical Properties

Existence & Uniqueness

A stable matching always exists (Gale & Shapley, 1962), but is not necessarily unique. For a given preference set there can be multiple stable matchings, and they form a lattice ordered by joint preference.

Proposer Optimality

When one side proposes, Gale-Shapley produces the proposer-optimal stable matching: every proposer receives the best partner they could possibly be paired with in any stable matching. By a symmetric argument, this is also the receiver-pessimal matching โ€” the receiving side gets their worst stable partner. Switching the proposing side in this calculator often changes the result.

Strategy Proofness for Proposers

Under Gale-Shapley, proposers have no incentive to misreport their preferences: telling the truth is a dominant strategy for them. Receivers, however, can sometimes benefit from strategic misreporting โ€” one of the reasons the hospital-residents market in the US is designed with students as the proposing side.

Rural Hospitals Theorem

The set of unmatched agents is identical across all stable matchings. So if your instance has unbalanced sizes (beyond the scope of this classic tool) the same people will be unmatched in every stable solution.

Input Format

This calculator expects one line per member, with name followed by a colon and a full ranked preference list separated by commas:

Name1: first choice, second choice, third choice, ..., last choice Name2: first choice, second choice, ... ...

Requirements:

How to Use This Calculator

  1. Enter preferences for Group A in the left text area โ€” one line per member, full ranked list.
  2. Enter preferences for Group B in the right text area โ€” one line per member, same format.
  3. Pick the proposing side. Choose Group A or Group B. Try both to compare the A-optimal vs B-optimal outcomes.
  4. Click "Solve Stable Matching." The calculator runs Gale-Shapley and produces the stable pairs, statistics, animation, and proof of stability.
  5. Scrub the animation with the play / step / reset controls to see every proposal, acceptance, swap, and rejection in order.
  6. Inspect the heatmap. Each cell shows the ranking; the yellow-outlined cells form the final matching โ€” look at how high or low those cells sit to see how "happy" each side is.

Worked Example โ€” The Classic 3ร—3

Men: Alex, Bryan, Chris. Women: Bea, Claire, Diana. Preferences:

Alex: Bea, Claire, Diana Bryan: Claire, Bea, Diana Chris: Diana, Bea, Claire Bea: Bryan, Alex, Chris Claire: Alex, Bryan, Chris Diana: Chris, Bryan, Alex

Running Gale-Shapley with men proposing yields Alexโ€“Bea, Bryanโ€“Claire, Chrisโ€“Diana in a single round (every man's first choice matches a woman whose first choice is someone else โ€” no conflict). The matching is stable: no man-woman pair would both be better off swapping partners, so there is no blocking pair.

Real-World Applications

Application Group A Group B Who proposes
NRMP Residency Match (US) Medical students Hospital programs Students โ€” designed to be student-optimal since 1998
NYC / Boston School Choice Families Public schools Families โ€” replaced a strategic-gaming mechanism in the 2000s
College Admissions Applicants Universities Originally Gale-Shapley's motivating example
Kidney Exchange Donor-recipient pairs Other donor-recipient pairs Specialized cycle-finding extension of matching theory
Dating & Roommate Matching Users Potential partners Consumer apps often use simplified versions of the same idea

Why Lloyd Shapley Won a Nobel Prize

In 2012 the Royal Swedish Academy of Sciences awarded the Nobel Prize in Economics to Lloyd Shapley (for the theory, alongside David Gale who had passed away) and Alvin Roth (for applying the theory to real markets, including redesigning the US medical residency match and kidney exchange networks). The award cited "the theory of stable allocations and the practice of market design."

Frequently Asked Questions

What is the stable marriage problem?

The stable marriage problem asks: given two equally-sized groups where each member ranks all members of the other group from most to least preferred, can we pair everyone up so that no two people would both prefer to leave their current partners for each other? Such a pairing is called a stable matching. The Gale-Shapley algorithm solves this problem in O(nยฒ) time and always finds a stable matching.

How does the Gale-Shapley algorithm work?

The Gale-Shapley deferred-acceptance algorithm proceeds in rounds. In each round, every currently-unengaged proposer proposes to the highest-ranked receiver on their list who has not yet rejected them. Each receiver tentatively accepts the best proposal received so far and rejects the rest; any displaced proposer becomes free again. The algorithm terminates when no proposer is free, which happens in at most nยฒ proposals.

Is the stable matching unique?

No. A stable matching instance can have many stable matchings. However, when one side proposes, Gale-Shapley always produces the proposer-optimal stable matching: every proposer gets the best partner they could possibly get in any stable matching. By symmetry, this is also the receiver-pessimal matching for the other side. Switching the proposing side often yields a different stable matching.

What is a blocking pair?

A blocking pair is a pair (a, b) that is not currently matched where a prefers b to their current partner AND b also prefers a to their current partner. If any blocking pair exists, the matching is unstable because those two would rather pair up with each other. A stable matching has no blocking pairs, which this calculator verifies automatically after each solve.

What are real applications of stable matching?

The Gale-Shapley algorithm powers the National Resident Matching Program that assigns medical students to residencies in the United States, school-choice systems in Boston and New York, college admissions in several countries, organ-donor kidney exchange chains, and roommate-assignment systems. Lloyd Shapley and Alvin Roth won the 2012 Nobel Prize in Economics partly for this work.

Do both groups need to be the same size?

In the classical stable marriage formulation, yes. Both sides must have the same number of members and each must provide a complete ranking of the other side. Unbalanced variants (such as the stable matching with incomplete lists or the hospital-residents problem) exist but require modified algorithms. This calculator enforces equal sizes and complete preference lists.

Further Reading

Reference this content, page, or tool as:

"Stable Marriage Problem Solver" at https://MiniWebtool.com/stable-marriage-problem-solver/ from MiniWebtool, https://MiniWebtool.com/

by miniwebtool team. Updated: Apr 22, 2026

You can also try our AI Math Solver GPT to solve your math problems through natural language question and answer.

Advanced Math Operations:

Top & Updated:

Random PickerRandom Name PickerInstagram User ID LookupImage ResizerLine CounterFPS ConverterRelative Standard Deviation CalculatorSort NumbersRemove SpacesFacebook User ID LookupMAC Address GeneratorBatting Average CalculatorERA CalculatorWord to Phone Number ConverterMAC Address LookupSlope and Grade CalculatorFeet and Inches to Cm ConverterMercury Retrograde CalendarSum Calculator๐Ÿ“ท OCR / Image to TextSun, Moon & Rising Sign Calculator ๐ŸŒž๐ŸŒ™โœจRandom Quote Generatorโฌ› Aspect Ratio CalculatorPercent Off CalculatorSHA256 Hash GeneratorInvisible Text GeneratorRandom Credit Card GeneratorMerge VideosRandom Truth or Dare GeneratorAudio SplitterMaster Number CalculatorMP3 LooperOPS CalculatorVertical Jump CalculatorBroken Link CheckerNumber of Digits CalculatorRandom IMEI GeneratorCompound Growth Calculator๐Ÿ–ฑ๏ธ Click CounterBitwise CalculatorRandom Superpower GeneratorLog Base 10 CalculatorCm to Feet and Inches ConverterSquare Root (โˆš) CalculatorFile Size ConverterRandom Poker Hand GeneratorRandom Activity GeneratorRoman Numerals ConverterPhone Number ExtractorWord Ladder GeneratorRandom Fake Address GeneratorSaturn Return CalculatorOctal CalculatorSalary Conversion CalculatorRandom Birthday GeneratorImage SplitterCaffeine Overdose CalculatorRandom Movie PickerBattery Life CalculatorYouTube Channel StatisticsSun Position CalculatorWeight Loss CalculatorText FormatterNumber to Word ConverterRandom Meal GeneratorCompare Two StringsRandom Writing Prompt GeneratorIP Subnet CalculatorSHA512 Hash GeneratorOn Base Percentage CalculatorAI Text HumanizerSlugging Percentage CalculatorHalfway Date CalculatorAdd Text to ImageStair CalculatorRandom Emoji GeneratorVideo to Image Extractor๐Ÿ“… Date CalculatorDecimal to BCD ConverterName RandomizerRandom Loadout GeneratorTime Duration CalculatorBcrypt Hash Generator / CheckerVideo CompressorList of Prime NumbersBinary to Gray Code ConverterProportion CalculatorLong Division CalculatorLunar Calendar ConverterArc Length CalculatorQuotient and Remainder CalculatorRatio to Percentage CalculatorCone Flat Pattern (Template) GeneratorPercent Growth Rate CalculatorYouTube Tag ExtractorFirst n Digits of PiMartingale Strategy CalculatorRemove AccentWAR CalculatorRemove Lines Containing...BCD to Decimal ConverterDay of the Year Calculator - What Day of the Year Is It Today?Gray Code to Binary ConverterWord Scramble GeneratorBingo Card GeneratorCM to Inches ConverterDMS to Decimal Degrees ConverterAPI TesterConnect the Dots GeneratorBreak Line by CharactersRandom User-Agent GeneratorAcreage CalculatorSmall Text Generator โฝแถœแต’แต–สธ โฟ แต–แตƒหขแต—แต‰โพFlip VideoLeap Years ListEmail ExtractorAstrological Element Balance CalculatorNumber ExtractorMD5 Hash GeneratorRandom Tournament Bracket GeneratorWHIP CalculatorWhat is my Lucky Number?Random Group GeneratorDistance Between Two Points CalculatorBolt Torque CalculatorAI Language DetectorWhat is my Zodiac Sign?๐ŸŽฐ Gacha Pity CalculatorOutlier CalculatorVideo SplitterIP Address to Hex ConverterModulo CalculatorDecibel (dB) CalculatorSocial Media Username CheckerRandom Chord GeneratorSourdough CalculatorLove Compatibility CalculatorHebrew Calendar ConverterTrigonometric Equation SolverAdjust Video SpeedBinary to BCD ConverterImage CompressorMolarity CalculatorName Number CalculatorLottery Number GeneratorAdd Prefix and Suffix to TextVoronoi Diagram GeneratorBeer Chill Time CalculatorHeight Percentile CalculatorDay of Year CalendarRandom Number PickerURL Extractor1099 Tax Calculator๐Ÿ’ง Dew Point CalculatorRandom Object GeneratorRandom Name GeneratorAmortization CalculatorMAC Address AnalyzerPercentage Increase CalculatorRandom Math Problem GeneratorReverse VideoColor InverterEffect Size Calculator๐Ÿ”Š Tone GeneratorLED Resistor CalculatorPercent to PPM ConverterPercentile CalculatorAI ParaphraserRandomize NumbersRemove Audio from VideoText RepeatHypotenuse Calculator๐Ÿ” Plagiarism CheckerSum of Positive Integers CalculatorRandom Time GeneratorPER CalculatorHTML CompressorRandom Chess Opening GeneratorHelium Balloon Lift CalculatorSort Text By LengthRemove Leading Trailing SpacesMandelbrot Set ExplorerBoiling Point CalculatorPVIFA CalculatorFirst n Digits of eRatio CalculatorList RandomizerRandom Excuse GeneratorMiter Angle CalculatorRotate VideoRandom Line PickerReverse TextYouTube Earnings EstimatorPVIF CalculatorNonogram Generator (Picross)Bonus CalculatorCollage MakerAI Punctuation AdderSort Lines AlphabeticallyHex to BCD ConverterBCD to Binary ConverterBCD to Hex ConverterMedian CalculatorStandard Error CalculatorAverage CalculatorActual Cash Value CalculatorScientific Notation to Decimal ConverterAngel Number CalculatorLog Base 2 CalculatorRoot Mean Square CalculatorSHA3-256 Hash GeneratorAI Sentence ExpanderLbs to Kg ConverterHex to Decimal ConverterConvolution CalculatorRandom String GeneratorMarkup CalculatorDecimal to Hex ConverterInstagram Font GeneratorSocial Media Image Size GuideTikTok Money CalculatorTwitter/X Character CounterTwitter/X Timestamp ConverterYouTube Watch Time CalculatorTwitch Earnings CalculatorYouTube Shorts Monetization CalculatorFacebook Ad Cost CalculatorSocial Media ROI CalculatorSocial Media Post Time OptimizerCTR CalculatorROAS CalculatorInfluencer ROI CalculatorForce CalculatorAcceleration CalculatorVelocity CalculatorMomentum CalculatorProjectile Motion CalculatorKinetic Energy CalculatorPotential Energy CalculatorWork and Power CalculatorDensity CalculatorPressure CalculatorIdeal Gas Law CalculatorFree Fall CalculatorTorque CalculatorHorsepower CalculatorDilution CalculatorChemical Equation BalancerStoichiometry CalculatorPercent Yield CalculatorEmpirical Formula CalculatorTitration CalculatorMole/Gram/Particle ConverterIrregular Polygon Area CalculatorFrustum CalculatorTorus Calculator3D Distance CalculatorGreat Circle Distance CalculatorCircumscribed Circle (Circumcircle) CalculatorInscribed Circle (Incircle) CalculatorAngle Bisector CalculatorTangent Line to Circle CalculatorHeron's Formula CalculatorCoordinate Geometry Distance CalculatorVolume of Revolution CalculatorSurface of Revolution CalculatorParametric Curve GrapherRiemann Sum CalculatorTrapezoidal Rule CalculatorSimpson's Rule CalculatorImproper Integral CalculatorL'Hรดpital's Rule CalculatorMaclaurin Series CalculatorPower Series CalculatorSeries Convergence Test CalculatorInfinite Series Sum CalculatorAverage Rate of Change CalculatorInstantaneous Rate of Change CalculatorRelated Rates SolverOptimization Calculator (Calculus)Gradient Calculator (Multivariable)Divergence CalculatorCurl CalculatorLine Integral CalculatorSurface Integral CalculatorJacobian Matrix CalculatorNewton's Method CalculatorRREF Calculator (Row Echelon Form)Matrix Inverse CalculatorMatrix Multiplication CalculatorDot Product CalculatorCross Product CalculatorVector Magnitude CalculatorUnit Vector CalculatorAngle Between Vectors CalculatorNull Space CalculatorColumn Space CalculatorCramer's Rule CalculatorMatrix Diagonalization CalculatorQR Decomposition CalculatorCholesky Decomposition CalculatorMatrix Power CalculatorCharacteristic Polynomial CalculatorBayes' Theorem CalculatorF-Test / F-Distribution CalculatorHypergeometric Distribution CalculatorNegative Binomial Distribution CalculatorGeometric Distribution CalculatorExponential Distribution CalculatorWeibull Distribution CalculatorBeta Distribution CalculatorSpearman Rank Correlation CalculatorFisher's Exact Test CalculatorContingency Table CalculatorOdds Ratio CalculatorBernoulli Equation CalculatorHeat Transfer CalculatorThermal Expansion CalculatorSpecific Heat Capacity CalculatorGear Ratio Calculator (Mechanical)Pulley System CalculatorHydraulic Cylinder Force CalculatorBelt Length CalculatorCloset Capsule CalculatorStorage Unit Size CalculatorMoving Box Quantity CalculatorGift Card Tip CalculatorGas vs Electric Cost ComparisonPrint Cost CalculatorHair Dye Mixing CalculatorLaundry Detergent Dosage CalculatorDishwasher Load OptimizerTile Grout CalculatorPaint Color Mixing CalculatorFlashcard Spaced Repetition SchedulerLearning Curve CalculatorCornell Notes GeneratorVocabulary Quiz GeneratorLanguage Learning Hours to Fluency CalculatorCollege Cost CalculatorScholarship ROI CalculatorAI Recipe Generator (From Ingredients)AI Gift Idea GeneratorAI Meal Plan GeneratorAI Workout Plan GeneratorAI Reading List GeneratorAI Travel Itinerary GeneratorAI Excuse Generator (Polite)AI Apology Letter WriterAI Unit Converter (Natural Language)AI Resume / CV AnalyzerAI Text Tone AnalyzerAI Data Visualizer (Paste CSV)AI Regex GeneratorAI SQL Query GeneratorPaycheck Calculator (Take-Home Pay)VA Loan CalculatorARM Mortgage CalculatorBiweekly Mortgage Payment CalculatorPMI CalculatorMortgage Points CalculatorBalloon Loan CalculatorInterest-Only Mortgage CalculatorConstruction Loan CalculatorLand Loan CalculatorBoat Loan CalculatorRV Loan CalculatorMotorcycle Loan CalculatorCar Affordability CalculatorOut-the-Door Price CalculatorRent Affordability CalculatorProrated Rent CalculatorRent Increase CalculatorMileage Reimbursement CalculatorPer Diem CalculatorInvoice GeneratorSalary Raise CalculatorSeverance Pay CalculatorHSA Calculator529 College Savings CalculatorI Bond CalculatorT-Bill CalculatorCD Ladder CalculatorCredit Utilization CalculatorLoan Comparison CalculatorGross-Up CalculatorSWP CalculatorRD CalculatorPPF CalculatorEPF CalculatorNPS CalculatorGratuity CalculatorHRA Exemption CalculatorUK Stamp Duty CalculatorZakat CalculatorTithe CalculatorBetting Odds ConverterPayPal Fee CalculatorStripe Fee CalculatorEtsy Fee CalculatoreBay Fee CalculatorAmazon FBA CalculatorShopify Profit CalculatorWholesale Price CalculatorCraft Pricing CalculatorDepreciation CalculatorEOQ CalculatorReorder Point CalculatorSafety Stock CalculatorFIFO / LIFO CalculatorContribution Margin CalculatorWorking Capital CalculatorCost Per Lead CalculatorEmail Marketing ROI CalculatorTip Pooling CalculatorWeek Number CalculatorAnniversary CalculatorHalf Birthday CalculatorSobriety CalculatorRetirement CountdownDate to Roman Numerals ConverterSunrise & Sunset CalculatorMoon Phase CalculatorNap CalculatorWorld ClockJulian Date ConverterISO 8601 Date FormatterChinese Gender PredictorImplantation CalculatorIVF Due Date CalculatorhCG Doubling Time CalculatorChild Height PredictorChild BMI Percentile CalculatorBaby Eye Color PredictorBaby Name GeneratorDiaper Size CalculatorBaby Milk Intake CalculatorCost of Raising a Child CalculatorEasy Grader (EZ Grader)CGPA to Percentage Converter