1

I'm currently in an advanced data structure class and learned a good bit about the graph. For this summer, I was asked to help write an algorithm to match roommates. Now for my data structure class, I've written a City Path graph and performs some sorting and prims algorithms and I'm sort of thinking that a graph may be a great place to start with my roommate matching algorithm.

I was thinking that our data base could just be a text file, nothing too fancy. However I could initialize each nodes in the graph as a student each student would have an un-directed edge to many more students (no edge to the student who doesn't want to be roommate with another one, the sorority also doesn't want repeating roommate). Now I could also make the edge weights more, depending on the special interest.

Everything listed above is quite simple and I don't think I'll run into any problem implementing it. But here is my question:

How should I update the common interest field? Should I start that with a physical survey and then go back into the text file and update the weight of the edge manually? Or should I be creating a field that keeps track of the matching interests?

double-beep
  • 5,031
  • 17
  • 33
  • 41
Nam Vu
  • 1,727
  • 1
  • 11
  • 24

1 Answers1

1

What you're trying to design is called bipartite matching. Fortunately unlike other bipartite matching algorithms, you won't need fancy graph algorithms and complex implementation for this. This is very close of Stable Marriage Problem and surprisingly there are very effective even easier algorithm for this.

If you are interested, I can share my C++ implementation of stable marriage problem.

Kaidul
  • 15,409
  • 15
  • 81
  • 150
  • 1
    @NamVu sure. Here you go https://github.com/kaidul/Data_Structure_and_Algorithms_Library/blob/master/algorithms/stable_marriage_problem.cpp – Kaidul Mar 06 '20 at 09:34
  • 1
    @NamVu The comments on the code is quite uncensored :p Ignore the comments – Kaidul Mar 06 '20 at 09:35
  • noted as per https://github.com/kaidul/Data_Structure_and_Algorithms_Library/blob/master/algorithms/stable_marriage_problem.cpp#L1 :) – Nam Vu Mar 06 '20 at 16:01