Repository navigation
feat(sorting): add counting sort - #40
Open
bh-official wants to merge 1 commit into
Open
bh-official wants to merge 1 commit into
bh-official wants to merge 1 commit into
Conversation
Add countingSort to the sorting visualizer: it tallies each value in a 100-slot count array, then writes the values back in order. Comparisons and swaps stay at 0 and writes end at n. Registered everywhere the contributing checklist lists: SORTERS, code snippets in five languages, catalog page and roadmap, explainer, comparison copy, README and practice problems. Adds a "write" bar role and tests for the new sorter. Closes salsadsid#11
|
@bh-official is attempting to deploy a commit to the salsadsid's projects Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #11
Adds counting sort to the sorting visualizer at
/algorithms/sorting/counting-sort.What changed
countingSortinsrc/lib/algorithms/sorting.jsplus itsSORTERSentry. It counts each value in a 100-slot array (one step per value, withvandcount[v]shown as variables), then writes the values back in order (one step per write). Comparisons and swaps stay at 0 and writes end at n.roles.js) so written slots do not look like shifts.i = 0.Tests
New tests in
tests/sorting.test.mjs: sorted output for random arrays, duplicates, single element, all equal, already sorted and reversed input; comparisons 0, swaps 0, writes == n; counting phase before write-back phase; no value lost or added. They failed before the change (noSORTERS.counting) and pass now.Ran
npm test: 127 pass, 0 fail (119 before)npm run lint: cleannpm run build: succeeds,/algorithms/sorting/counting-sortis generatedNotes
complexity.stableis "N/A": the visualizer rewrites plain numbers, so stability cannot be observed, and the explainer FAQ says why. Easy to change to "Yes" if you prefer the textbook label.keyrole while a value is read, the newwriterole for each write, andsortedfor the filled prefix.