0% found this document useful (0 votes)
29 views1 page

To Calculate All Arrangements in O

The document describes two algorithms for calculating all arrangements of matching men and women in different time complexities. The first algorithm matches each man with his top preference among remaining women in O(n(n!)) time. The second algorithm uses the Gale-Shapley stable matching algorithm on subsets of men to calculate all arrangements in O(n^2(2^n)) time.

Uploaded by

RajeevDutt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views1 page

To Calculate All Arrangements in O

The document describes two algorithms for calculating all arrangements of matching men and women in different time complexities. The first algorithm matches each man with his top preference among remaining women in O(n(n!)) time. The second algorithm uses the Gale-Shapley stable matching algorithm on subsets of men to calculate all arrangements in O(n^2(2^n)) time.

Uploaded by

RajeevDutt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

a) To calculate all arrangements in O((n)n!

) time, we take first man and match


him with n females, and engage him with his top preference, we continue this
and in next iteration engage the second men with his top most preference
out of the left n-1 women and so on till every one is engaged. so we match n
men so..1st man with n women,2nd man with n-1 women ,3rd with n-2 and so
on..We get O(n(n!))
Pseudo code: maintain a queue of men and queue of women in form of array or
linked list...deque first man and start traversing the women queue the first place
where compatibility occurs ,connect that women and men(by making index of
women array equal to that of matched men).terminate the traversing. Again deque
a man and repeat the process.

b)to calculate all arrangements in the given time, first we make an arbitrary subset
of a male group and then use stable matching GaleShapley algorithm(tell me if u
dnt know this)..so what it does is gale shapley gives us a stable matching in o(n^2)
time ,and we in all can make (2^n) subsets from n men ,hence the time
O(n^2(2^n))

You might also like