Sei sulla pagina 1di 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))

Potrebbero piacerti anche