解释什么是快速排序算法?_解释排序算法

解释什么是快速排序算法?

Sorting algorithms are a set of instructions that take an array or list as an input and arrange the items into a particular order.

排序算法是一组指令,这些指令采用数组或列表作为输入并将项目按特定顺序排列。

Sorts are most commonly in numerical or a form of alphabetical (called lexicographical) order, and can be in ascending (A-Z, 0-9) or descending (Z-A, 9-0) order.

排序最常见的是数字形式或字母顺序(称为字典顺序),并且可以升序(AZ,0-9)或降序(ZA,9-0)顺序。

为什么排序算法很重要 (Why Sorting Algorithms are Important)

Since sorting can often reduce the complexity of a problem, it is an important algorithm in Computer Science. These algorithms have direct applications in searching algorithms, database algorithms, divide and conquer methods, data structure algorithms, and many more.

由于排序通常可以降低问题的复杂性,因此它是计算机科学中的重要算法。 这些算法可直接应用于搜索算法,数据库算法,分治法,数据结构算法等等。

一些常见的排序算法 (Some Common Sorting Algorithms)

Some of the most common sorting algorithms are:

一些最常见的排序算法是:

  • Selection Sort

    选择排序
  • Bubble Sort

    气泡排序
  • Insertion Sort

    插入排序
  • Merge Sort

    合并排序
  • Quick Sort

    快速排序
  • Heap Sort

    堆排序
  • Counting Sort

    计数排序
  • Radix Sort

    基数排序
  • Bucket Sort

    桶分类

排序算法分类 (Classification of Sorting Algorithm)

Sorting algorithms can be categorized based on the following parameters:

可以根据以下参数对排序算法进行分类:

  1. Based on Number of Swaps or Inversion This is the number of times the algorithm swaps elements to sort the input. Selection Sort requires the minimum number of swaps.

    基于交换次数或反转次数这是算法交换元素以对输入进行排序的次数。 Selection Sort要求最少数量的交换。

  2. Based on Number of Comparisons This is the number of times the algorithm compares elements to sort the input. Using Big-O notation, the sorting algorithm examples listed above require at least O(nlogn) comparisons in the best case and O(n^2) comparisons in the worst case for most of the outputs.

    基于比较次数这是算法比较元素以对输入进行排序的次数。 使用Big-O表示法 ,上面列出的排序算法示例在大多数情况下对于大多数输出​​至少需要O(nlogn)比较,而在最坏情况下至少需要O(n^2)比较。

  3. Based on Recursion or Non-Recursion Some sorting algorithms, such as Quick Sort, use recursive techniques to sort the input. Other sorting algorithms, such as Selection Sort or Insertion Sort, use non-recursive techniques. Finally, some sorting algorithm, such as Merge Sort, make use of both recursive as well as non-recursive techniques to sort the input.

    基于递归或非递归一些排序算法(例如Quick Sort )使用递归技术对输入进行排序。 其他排序算法(例如Selection SortInsertion Sort )使用非递归技术。 最后,一些排序算法(例如Merge Sort )利用递归和非递归技术对输入进行排序。

  4. Based on Stability Sorting algorithms are said to be stable if the algorithm maintains the relative order of elements with equal keys. In other words, two equivalent elements remain in the same order in the sorted output as they were in the input.

    基于稳定性的排序算法被认为是stable是该算法使用相同的键维持元素的相对顺序。 换句话说,两个等效元素在排序输出中的顺序与输入中的顺序相同。

  5. Insertion sort, Merge Sort, and Bubble Sort are stable

    Insertion sortMerge SortBubble Sort稳定

  6. Heap Sort and Quick Sort are not stable

    Heap SortQuick Sort不稳定

  7. Based on Extra Space Requirement Sorting algorithms are said to be in place if they require a constant O(1) extra space for sorting.

    基于额外空间要求,如果排序算法需要恒定的O(1)额外空间来进行排序,则可以说已经in place

  8. Insertion sort and Quick-sort are in place sort as we move the elements about the pivot and do not actually use a separate array which is NOT the case in merge sort where the size of the input must be allocated beforehand to store the output during the sort.

    Insertion sortQuick-sortin place我们围绕枢轴移动元素时in place排序,实际上并没有使用单独的数组,在合并排序中情况并非如此,在合并排序中,必须事先分配输入的大小以在输出期间存储输出分类。

  9. Merge Sort is an example of out place sort as it require extra memory space for it’s operations.

    Merge Sort是一个例子out place的排序,因为它需要它的运营的额外存储空间。

任何基于比较的排序的最佳时间复杂度 (Best possible time complexity for any comparison based sorting)

Any comparison based sorting algorithm must make at least nLog2n comparisons to sort the input array, and Heapsort and merge sort are asymptotically optimal comparison sorts.This can be easily proved by drawing the decision tree diagram.

任何基于比较的排序算法都必须至少进行nLog2n个比较才能对输入数组进行排序,而Heapsort和merge排序是渐近最优的比较排序,这可以通过绘制决策树图轻松证明。

翻译自: https://www.freecodecamp.org/news/sorting-algorithms-explained/

解释什么是快速排序算法?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值