Python
Python copied to clipboard
Feature best match finder
Describe your change:
- [x] Add an algorithm?
- [ ] Fix a bug or typo in an existing algorithm?
- [ ] Documentation change?
Checklist:
- [x] I have read CONTRIBUTING.md.
- [x] This pull request is all my own work -- I have not plagiarized.
- [x] I know that pull requests will not be merged if they fail the automated tests.
- [x] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
- [x] All new Python files are placed inside an existing directory.
- [x] All filenames are in all lowercase characters with no spaces or dashes.
- [x] All functions and variable names follow Python naming conventions.
- [x] All function parameters and return values are annotated with Python type hints.
- [ ] All functions have doctests that pass the automated testing.
- [x] All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
- [ ] If this pull request resolves one or more open issues then the commit message contains
Fixes: #{$ISSUE_NO}.
Best Match Finder Algorithm
Implemented the best match finder algorithm as discussed in the MITOCW video lecture for the course 6.042 by Prof. Tom Leighton. The link above leads to the timestamp where he starts explaining how the algorithm works, using an example.
The problem is as follows:
- We are given two groups with same number of elements
- Each element has a preference order, ranking the elements in the descending order in which the element wants to pair with them, i.e. 1st element is most preferred and last element is least preferred
- We are given the task to find out such a matching of the elements such that there are no rogue couples
- Rogue couple is a set of two elements from different groups that have a higher preference for each other than the element they have currently been paired up with.
EXAMPLE Let
g,fbe two sets whose elements are to be matched Let(g1, f1)and(g2, f2)be matched but
g2has higher preference forf1thanf2f1has higher preference forg2thang1In such a case,g2andf1are a rogue couple
The best matching is achieved when there are no rogue couples. Also for any two groups with the specifications as given above, there exists a best match. Proof in video lecture
Added type hints, also created the test file and took out the nested functions
I have written the code by import from the typing module in python
from typing import List, Dict, Tuple
But this bot keeps changing all the occurences of List, Dict, Tuple to list, dict, tuple respectively resulting in an error for unused imports. And using list, dict, tuple also gives an error for types cannot be indexed. What should I do now?
Closing due to lack of response to code review