Counting sorting and C language implementation

Source: Internet
Author: User


In the previous discussion, the insertion sort, merge sort, heap sort and quick sort are all based on the comparison sorting algorithm, and for all the comparison sorting algorithms, the complexity of the algorithm is also O (NLGN). For the proof process, refer to the eighth chapter of the Introduction to Algorithms section I.


Today introduces a non-comparative sort, named Count sort.

The basic idea is that for each element, the element is determined to be less than the number of the element, and it can be placed in the correct position. The algorithm can achieve linear time complexity, i.e. O (n).


Program, array A is an input array (unordered array), B is an output array, and C is an intermediate array. 20 means that each element in the array is assumed to be a nonnegative integer less than 20.


Counting sorting and C language implementation

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.