Question: Problem 4 . [ Category: Stable matching ] Recall in Homework 4 where you worked on the unhappy friends problem: You are given a list

Problem 4.[Category: Stable matching]
Recall in Homework 4 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 erences[i]
contains a list of friends sorted in the order of preference. Friends in each list are denoted by integers from 0
to n 1. All the friends are divided into pairs. The pairings are given in a list pairs, where pairs[i]=[xi, 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 =4, preferences =[[3,2,1],[2,3,0],[1,3,0],[1,2,0]], pairs =[[0,1],[2,3]]
Output:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!