Algorithm: Bucket sequencing

Source: Internet
Author: User

Pass sorting is a waste of space, such as the range that needs to be sorted 0~2000 between, the number that needs to be sorted is [3,9,4,2000], also need 2001 space

Note: sorting cannot sort decimals

def bucketsort (nums):
# Select a maximum number
Max_num = max (nums)
# Create an element that is all a list of 0, as a bucket
bucket = [0]* (max_num+1)
# put all the elements into the bucket, that is, the number of corresponding elements plus one
For I in Nums:
Bucket[i] + = 1

# Store sorted elements
Sort_nums = []
# Remove the elements from the bucket
For j in Range (len):
If BUCKET[J]! = 0:
For y in range (Bucket[j]):
Sort_nums.append (j)

Return sort_nums

Nums = [5,6,3,1,65,2]
Print (Bucketsort (nums))
X

Algorithm: Bucket sequencing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.