Python implements bucket ordering of data structures and algorithms

Source: Internet
Author: User

Bucket sort

Barrel sequencing has been used since the 1956, and the basic idea of the algorithm is proposed by E.J.ISSAC and R.c.singleton.

This algorithm is like having 11 barrels, numbered from 0~10. Each occurrence of a number, in the corresponding number of buckets put a
A little flag, and then just count the few small flags in each bucket OK. For example, there are 1 small flags in bucket 2nd, indicating
2 appeared once, and in the 3rd barrels there were 1 small flags, indicating that 3 appeared once, and 5th were in the barrels of 2 flags, indicating 5
Appeared two times, and in 8th barrels there were 1 small flags, indicating that 8 appeared once.

Code
1 defMain ():2Book =list ()3      for_inchRange (1001):4 book.append (0)5 6n = Int (input ('Number of buckets to sort by:'))7 8      for_inchrange (n):9t =int (input ())TenBOOK[T] + = 1 One  A      forIinchReversed (Range (1,1001)): -          forJinchRange (Book[i]): -             PrintI the  - if __name__=='__main__': -Main ()

Python implements bucket ordering of data structures and algorithms

Related Article

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.