Question: Problem 4 . [ Category: Stable matching ] Recall in Homework 4 where you worked on the unhappy friends problem: You are given a list
Problem Category: Stable matching
Recall in Homework where you worked on the unhappy friends problem:
You are given a list of preferences for n friends, where n is always even. For each person i pref erencesi
contains a list of friends sorted in the order of preference. Friends in each list are denoted by integers from
to n All the friends are divided into pairs. The pairings are given in a list pairs, where pairsixi yi
denotes xi is paired with yi and yi is paired with xi
However, this pairing may cause some of the friends to be unhappy. A friend x is unhappy if x is paired
with y and there exists a friend a who is paired with b but:
x prefers a over y and a prefers x over b Return the number of unhappy friends.
Given the the preferences and pairs input like below, whats output the count of unhappy friends will be
Justify your answer briefly. you can run the input directly with your homework submission script.
Input: n preferences pairs
Output:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
