trekhleb / trekhleb/javascript-algorithms
QuickSort : Instead of taking pivot as 1st element, we should take the pivot as last element, due to time complexity
Open
Nobody has claimed this yet.
enhancement
- Dominant language
- JavaScript
- Stars
- 197k
- Forks
- 31k
- PR merge metrics
- No merged PRs in 30d
Description
Instead of this
const pivotElement = array.shift(); // O(n)
we should use
const pivotElement = array.pop(); // O(1)
When taking the pivot as last element 2 test cases are failing.
- QuickSort › should do stable sorting
- QuickSort › should visit NOT SORTED array element specified number of times
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the QuickSort implementation where the pivot is selected, then run the two named failing tests: stable sorting and visiting unsorted elements the specified number of times. Done means the pivot change improves the stated complexity without breaking either test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- data
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100