arraynodeSorting

本文介绍了常见的排序算法,包括插入排序、选择排序等,并对比了它们的时间复杂度与稳定性。此外,还详细解释了计数排序、桶排序及基数排序的工作原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

发一下牢骚和主题无关:

    

    sorting algorithm is an algorithm that puts elements of a list in a certain order. The most-used orders are numerical order and lexicographical order. There are two mainly kind of sorting algorithms.

    

    

    

    

        

    

2) distribution based sorting algorithms.

    

  • Counting Sort - A simple and fast sorting algorithm that creates an integer array of size |S| and using the ith bin to count the occurrences of the ith member of S in the input. Each input is then counted by incrementing the value of its corresponding bin. Afterward, the counting array is looped through to arrange all of the inputs in order.
  • Bucket Sort - A complex and fast sorting algorithm that divides an array into a finite number of buckets. Each bucket is then sorted individually, either using a different sorting algorithm, or by recursively applying the bucket sorting algorithm. Bucket sort is a generalization of Counting Sort and is a cousin of Radix Sort.
  • Radix Sort - A complex and fast sorting algorithm that  sorts the array by the least significant radix first and  then do the same process to second-least significant radix, until we get to the most significant radix, at which point the final result is a properly sorted list.

    

    

Comparison Table Of Different Sorting Algorithms
Soring   Algorithm             Stability       Space ComplexityTime Complexity (Ave.)Time Complexity (Worst.)Time Complexity (Best.)
Insertion Sort      
    
YesO(1)O(n^2)O(n^2)O(n)
Selection Sort
                   
YesO(1)O(n^2)
O(n^2)
O(n^2)
Bubble Sort

YesO(1)O(n^2)
O(n^2)
O(n)
Quick Sort

NoO(logn)O(nlogn)O(n^2)
O(nlogn)
Merge Sort

YesO(n)O(nlogn)
O(nlogn)
O(n)
Heap Sort

NoO(1)O(nlogn)
O(nlogn)
O(nlogn)
Shell Sort

NoO(1)NILO(n^2)O(n^1.3),
n in some range     


Counting Sort
NILO(k)O(n+k)NILNIL

Bucket Sort
NILO(n*k)NILO(n^2)O(n+k)

Radix Sort
YesO(r)
r is the radix     
O(d(n+r))
d is the length of max digit     
NIL
NIL
    每日一道理
如果你们是蓝天,我愿做衬托的白云;如果你们是鲜花,我愿做陪伴的小草;如果你们是大树,我愿做点缀的绿叶……我真诚地希望我能成为你生活中一个欢乐的音符,为你的每一分钟带去祝福。

    

Lower bound for comparison based sorting algorithms

    
The problem of sorting can be viewed as following.

    

    Input:

    

    A sequence of n numbers <a1, a2, . . . , an>.

    

    Output:

    

    A permutation (reordering) <a‘1, a‘2, . . . , a‘n> of the input sequence such that a‘1 <= a‘2 ….. <= a‘n.

    A sorting algorithm is comparison based if it uses comparison operators to find the order between two numbers. Comparison sorts can be viewed abstractly in terms of decision trees. The execution of the sorting algorithm corresponds to tracing a path from the root of the decision tree to a leaf. At each internal node, left subtree dictates subsequent comparisons for ai < aj, and the right subtree dictates subsequent comparisons for ai > aj. When we come to a leaf, the sorting algorithm has established the ordering. So we can say following about the decison tree.

    1) Each of the n! permutations on n elements must appear as one of the leaves of the decision tree for the sorting algorithm to sort properly.

    After combining the above two facts, we get following relation.

     

    Taking Log on both sides.

    

array和node

    <= x

Since 

    array和node

    =

    array和node

    ,  we can say

    x = 

    array和node

    
Therefore, any comparison based sorting algorithm must make at least array和node  comparisons to sort the input array, and Heap Sort and Merge Sort are asymptotically optimal comparison sorts.

    

    

References

    

    

    

文章结束给大家分享下程序员的一些笑话语录: 那是习惯决定的,一直保持一个习惯是不好的!IE6的用户不习惯多标签,但是最终肯定还是得转到多标签的浏览器。历史(软件UI)的进步(改善)不是以个人意志(习惯)为转移的!

--------------------------------- 原创文章 By
array和node
---------------------------------

转载于:https://www.cnblogs.com/jiangu66/archive/2013/05/31/3111538.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值