Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Bucket sort
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Pseudocode== '''function''' bucketSort(array, k) '''is''' buckets β new array of k empty lists M β 1 + the maximum key value in the array '''for''' i = 0 '''to''' length(array) '''do''' insert ''array[i]'' into ''buckets[floor(k Γ array[i] / M)]'' '''for''' i = 0 '''to''' k '''do''' nextSort(buckets[i]) '''return''' the concatenation of buckets[0], ...., buckets[k] Let ''array'' denote the array to be sorted and ''k'' denote the number of buckets to use. One can compute the maximum key value in [[linear time]] by iterating over all the keys once. The [[floor function]] must be used to convert a floating number to an integer ( and possibly casting of datatypes too ). The function ''nextSort'' is a sorting function used to sort each bucket. Conventionally, [[insertion sort]] is used, but other algorithms could be used as well, such as ''[[selection sort]]'' or ''[[merge sort]]''. Using ''bucketSort'' itself as ''nextSort'' produces a relative of [[radix sort]]; in particular, the case ''n = 2'' corresponds to [[quicksort]] (although potentially with poor pivot choices).
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)