Open
Conversation
eliemada
reviewed
May 3, 2025
| ``` | ||
| CountingSort(array, max_value) | ||
| Let count be an array with a length equal to max_value. All elements are in count are equal to -1. | ||
| Ler output be an array of same length as array |
eliemada
reviewed
May 3, 2025
|
|
||
| ``` | ||
| CountingSort(array, max_value) | ||
| Let count be an array with a length equal to max_value. All elements are in count are equal to -1. |
Member
There was a problem hiding this comment.
All elements shall be at 0
e.g
https://en.wikipedia.org/wiki/Counting_sort
eliemada
requested changes
May 3, 2025
| CountingSort(array, max_value) | ||
| Let count be an array with a length equal to max_value. All elements are in count are equal to -1. | ||
| Ler output be an array of same length as array | ||
|
|
Member
There was a problem hiding this comment.
add comment
// count occurence, of each element,
|
|
||
| for i in array: | ||
| count[i - 1] = count[i - 1] + 1 | ||
|
|
Member
There was a problem hiding this comment.
// Calculate cumulative count (position)
|
|
||
| for i to length(count) - 1: | ||
| count[i + 1] = count[i + 1] + count[i] | ||
|
|
Member
There was a problem hiding this comment.
// Place elements in sorted order
| count[i + 1] = count[i + 1] + count[i] | ||
|
|
||
| # sorting using count | ||
| for i in range(len(array)): |
Member
There was a problem hiding this comment.
This shall be in reversed order
Member
There was a problem hiding this comment.
for num in reversed(array): # Process in reverse for stability
index = count[num - 1] - 1
output[index] = num
count[num - 1] -= 1| for i to length(count) - 1: | ||
| count[i + 1] = count[i + 1] + count[i] | ||
|
|
||
| for i to length(array): |
Member
There was a problem hiding this comment.
for i = length(array)-1 down to 0:
output[count[array[i]]-1] = array[i]
count[array[i]] -= 1
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 #34