以下是各种排序算法的基本概述和复杂度分析:
冒泡排序 (Bubble Sort): 稳定排序,时间复杂度为 O(n^2)。
鸡尾酒排序 (Cocktail Sort): 双向冒泡排序,时间复杂度同样为 O(n^2)。
插入排序 (Insertion Sort): 时间复杂度为 O(n^2)。
桶排序 (Bucket Sort): 平均时间复杂度 O(n),但需要额外的 O(k) 空间。
计数排序 (Counting Sort): 时间复杂度 O(n+k),需要 O(n+k) 额外空间。
合并排序 (Merge Sort): 时间复杂度 O(nlog n),需要 O(n) 额外空间。
原地合并排序: 时间复杂度 O(n^2),但空间效率较高。
二叉排序树 (Binary Tree Sort): 期望时间 O(nlog n),最坏情况 O(n^2),需要 O(n) 额外空间。
鸽巢排序 (Pigeonhole Sort): 时间复杂度 O(n+k),需要 O(k) 额外空间。
基数排序 (Radix Sort): 时间复杂度 O(n·k),同样需要 O(n) 额外空间。
Gnome Sort: 时间复杂度 O(n^2)。
图书馆排序 (Library Sort): 高概率下时间复杂度 O(nlog n),需要额外空间 (1+ε)n,不稳定。
选择排序 (Selection Sort): 不稳定排序,时间复杂度 O(n^2)。
希尔排序 (Shell Sort): 最佳版本下时间复杂度 O(nlog n)。
组合排序: 时间复杂度 O(nlog n)。
堆排序 (Heapsort): 时间复杂度 O(nlog n)。
平滑排序 (Smooth Sort): 期望时间复杂度 O(nlog n)。
快速排序 (Quicksort): 期望时间 O(nlog n),最坏情况 O(n^2),在乱数列表中表现良好。
Introsort: 时间复杂度 O(nlog n)。
Patience Sorting: 时间复杂度 O(nlog n+ k),需要额外空间 O(n+ k),用于最长递增子串。
非实用排序算法: 如 Bogo Sort (O(n× n!)) 和 Stupid Sort (O(n^3)),前者期望时间长,最坏情况无穷,后者需要大量额外存储。
特殊硬件依赖: 如珠排序 (Bead Sort) 和 Pancake Sorting,时间复杂度较低,但需要特殊硬件支持。
stooge sort: 时间复杂度 O(n^2.7),虽然美观但效率不高。
扩展资料所谓排序,就是使一串记录,按照其中的某个或某些关键字的大小,递增或递减的排列起来的操作。