Skip to content
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

fix: adding median of three technique and module interface to QuickSortRecursive.js and its test file #1686

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

Conversation

stormkid2009
Copy link

Open in Gitpod know more

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

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, please open separate PRs for separate algorithms.
  • All new JavaScript files are placed inside an existing directory.
  • All filenames should use the UpperCamelCase (PascalCase) style. There should be no spaces in filenames.
    Example:UserProfile.js is allowed but userprofile.js,Userprofile.js,user-Profile.js,userProfile.js are not
  • All new algorithms have a URL in their comments that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 96.92308% with 2 lines in your changes missing coverage. Please review.

Project coverage is 84.68%. Comparing base (9010481) to head (e573010).

Files with missing lines Patch % Lines
Sorts/QuickSortRecursive.js 96.92% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1686      +/-   ##
==========================================
+ Coverage   84.65%   84.68%   +0.02%     
==========================================
  Files         378      378              
  Lines       19744    19791      +47     
  Branches     2951     2957       +6     
==========================================
+ Hits        16715    16760      +45     
- Misses       3029     3031       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

* Sorts the input list using the quicksort algorithm.
*
* @param {Array} inputList - the list to be sorted
* @return {Array} the sorted list
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we mutate the array anyways, it's unnecessary to return it, and IMO cleaner not to.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are absolutely right ,thanks for reminding me .

@@ -43,23 +58,55 @@ const quickSort = (inputList, low, high) => {
* @returns {number} `pIndex` pivot index value.
*/
const partition = (partitionList, low, high) => {
const pivot = partitionList[high]
const mid = Math.floor((low + high) / 2)
// get the median of three is good technique for partitioning to be sure that the 2 sub-arrays will be almost equal or nearly equal in size
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is phrased a bit poorly and also misleading: Nothing is guaranteed here. It's just a heuristic. It can still be horribly wrong if the arrays are crafted to be worst case.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am with you that nothing guaranteed but trying to improve something worth it.


// Move pivot to the end
let pivotIndex = partitionList.indexOf(pivot)
;[partitionList[pivotIndex], partitionList[high]] = [
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename some variables to make this less verbose.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok that will be better

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

Successfully merging this pull request may close these issues.

3 participants