Introduction to Algorithms learning Notes--The 8th chapter linear time Sequencing

Source: Internet
Author: User

Any sort of comparison algorithm, the worst-case operating time limit is Ω (NLGN)

Count sort

Assuming that each of the N input elements is an integer between 0 and K, K is an integer, and when K=o (N), the run time of the count sort is θ (n)

1 //input Array A[1..N], holding the sorted result array B[1..N], temporary storage C[0..K]2counting-SORT (a,b,k)3  fori←0to K4      Doc[i]←05  forj←1To Length[a]6      Doc[a[j]]←c[a[j]]+17  fori←1to K8      Doc[i]←c[i]+c[i-1]9  forJ←length[a] Downto1Ten      DoB[c[a[j]]]←a[j] Onec[a[j]]←c[a[j]]-1

Base sort

Assuming that the length is N of array A, each element has a D-digit number, where the 1th bit is the lowest, and the D-bit is the highest bit

1 radix-SORT (a,d)2 for i←1 to D3do      use a stable sort to sort array a on digit I

Bucket sort

Assuming that the input is produced by a random process, the process distributes the elements evenly across the interval [0,1]

1bucket-SORT (A)2 N←length[a]3  fori←1To N4      DoInsert a[i] into List B[floor (Na[i])5  fori←0to n16      Dosort list B[i] with insertion sort7Concatenate the lists b[0],b[1]... b[n-1] TogetherinchOrder

Introduction to Algorithms learning Notes--The 8th chapter linear time 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.