Reputation: 191
There is a set of 9 students and 3 schools Every school can be alloted at max 3 students .Every school and student has its coordinates .Now we have to allot student in such a way that the sum of distance from all the student to the school should be minimum.
I was asked this question in an interview.Can anyone suggest an algorithm for this?
Initially I tried greedy approach but that does not work.Then I tried applying a dynamic programming approach but could not come up with an optimal sub-structure.
Upvotes: 3
Views: 223
Reputation: 47367
How about exhaustive search since the problem size is small enough?
So (9 choose 3) * (6 choose 3) = 1680
Upvotes: 1
Reputation: 24677
Every school has 3 places, all 3 schools have 9 places. And you should find the best match between 9 places and 9 students.
This assignment problem may be solved with Hungarian algorithm.
Upvotes: 4