三种排序算法及复杂度
Sorting Algorithms
题目详情
对 个互不相同的值 ,解释三种排序算法及其时间/空间复杂度。
Explain 3 sorts for distinct values with complexities.
解析
示例:
-
插入排序:逐个插入已排序前缀。时间 ,空间 。
-
归并排序:分治+合并。时间 ,空间 。
-
快速排序:选 pivot 分区递归。平均 ,最坏 。
Original Explanation
- Insertion sort: place each new item into the correct position in the sorted prefix. time, space.
- Merge sort: divide & conquer, merges sublists. time, space.
- Quick sort: pick pivot, partition, recurse. Average , worst .