In2006,thecityofBeijing,China,institutedapolicythatlimitsresidentstoown at most one dog per household. Imagine you are running an online pet adoption website for the city. Your website contains pictures of adorable puppies that are available for adoption, and it allows for dogless Beijing residents to click on as many puppies as they like, with the understanding that they can adopt at most one. Suppose now that you have collected the puppy preferences from among n Beijing residents for your m puppies.
1) Describe an efficient algorithm for assigning puppies to residents that provides for the maximum number of puppy adoptions possible while satisfying the constraints that each resident will only adopt a puppy that he or she likes and that no resident can adopt more than one puppy.
2) State no. of V's and E's of network
3) Asymptotic running time
1. Problem is very simple to solve using max-flow problem where we will create vertex set P of size m where each vertex represent a puppy and we create a vertex set R of size n which represent residents of Beijing. There will be a directed edge (u,v) of capacity 1 where u is in P and V is in R if puppy u can be adopted by resident v.
We will create a source vertex s from which there will be edge to every vertex in P with capacity 1.
We will create a target vertex t such that every vertex in R has edge towards t with capacity 1.
Claim :- Max-flow from s to t will assign maximum possible number of puppies to residents of Beijing.
Proof :- Since puppy u will assign to resident v if and only if v has choice for u. And since edge capacity is 1 for every edges between P and R, so max-flow from s to t will be at most equal to number of edges between P and R having unit flow and also since every vertex in P can receive at most 1 unit flow from s and every vertex in R pass almost 1 unit flow to t, hence there will be at most 1 flow edge between any vertex pair from P to R.
Hence passing max-flow from s to t will maximize the possible assignment.
2. |V| = m+n+2 ,where m is number of pets, n is number of residents and 2 is vertex s and t.
|E|= m+n + number of choice between pet and residents
3. Time complexity = O(|V|2|E|) if we use Edmonds - Karp algorithm.
Please comment for any clarification.
In2006,thecityofBeijing,China,institutedapolicythatlimitsresidentstoown at most one dog per household. Imagine you are running an online pet adoption website...