Skip to content

Added Count Inversions algorithm (Merge Sort based) #12696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

usman-7455
Copy link

Describe your change:

  • Add an algorithm

This pull request adds a Python implementation of the Count Inversions algorithm using a modified Merge Sort approach.

Count Inversions is used to determine how far an array is from being sorted by counting the number of out-of-order pairs (i, j) such that i < j and arr[i] > arr[j]. This has applications in ranking systems, bioinformatics, and measuring list similarity.

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, I am not combining unrelated changes.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes. (Note: The filename is Count_Inversion.py; I can rename it to count_inversion.py if needed.)
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.

Wikipedia link: https://en.wikipedia.org/wiki/Inversion_(discrete_mathematics)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant