ps1num1c - then for n = k, the algorithm will attempt to...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
1(c). Input: Give the applicant set {A1, A2, …, An} and the job set {J1, J2, …, Jn} such that every applicant and every job ranks the other in exactly the reverse order. E.g. each applicant has preference in the order of {Jn, Jn-1, …, J1} and each job has preference in the order of {An, An-1, …, A1}. Complexity : The above input will cause the program to run in O (n!) which is exponential. Base case: if we’re given that n = 1, then there’s exactly one matching between J1 and A1, which is stable by default. So one operation is performed which is exponential in 1. Note : at every step within the subproblem of k<n, if Ak – Jn are not matched, the marriage is unstable because each whoever Ak is matched with will be higher on his preference list than Jn and vice versa for Jn to Ak. Assume that for some n=k-1, the running time for the function of our inputs A and J is O((n-1)!),
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: then for n = k, the algorithm will attempt to make matches until the An-Jn match is made, at which time the marriage will finally become stable. Since each iteration within the for loop removes Jn and Ai to be matched up later, the recursive call will be made on an applicant set A and a job set J of cardinality k-1 and of which every element of each set have a list of preference into the other set in the exact opposite order, which can be exchanged exactly as the input for the subproblem of n=k-1, which from the induction hypothesis takes O ((n-1)!) time to solve. However, since we can guarantee that no set of marriages are stable until the An-Jn match is made, which doesnt happen until after the for loop iterates for n steps, we will have to solve the same subproblem of order O((n-1)!) n times, making for O(n!) complexity....
View Full Document

Ask a homework question - tutors are online