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

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

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/

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/390602.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

SpringBoot自动化配置的注解开关原理

我们以一个最简单的例子来完成这个需求:定义一个注解EnableContentService,使用了这个注解的程序会自动注入ContentService这个bean。 Retention(RetentionPolicy.RUNTIME) Target(ElementType.TYPE) Import(ContentConfiguration.class) public interfa…

hadoop将消亡_数据科学家:适应还是消亡!

hadoop将消亡Harvard Business Review marked the boom of Data Scientists in their famous 2012 article “Data Scientist: Sexiest Job”, followed by untenable demand in the past decade. [3]《哈佛商业评论 》在2012年著名的文章“数据科学家:最性感的工作…

剑指 Offer 15. 二进制中1的个数 and leetcode 1905. 统计子岛屿

题目 请实现一个函数,输入一个整数(以二进制串形式),输出该数二进制表示中 1 的个数。例如,把 9 表示成二进制是 1001,有 2 位是 1。因此,如果输入 9,则该函数输出 2。 示例 1&…

[转]kafka介绍

转自 https://www.cnblogs.com/hei12138/p/7805475.html kafka介绍1.1. 主要功能 根据官网的介绍,ApacheKafka是一个分布式流媒体平台,它主要有3种功能: 1:It lets you publish and subscribe to streams of records.发布和订阅消…

如何开始android开发_如何开始进行Android开发

如何开始android开发Android开发简介 (An intro to Android Development) Android apps can be a great, fun way to get into the world of programming. Officially programmers can use Java, Kotlin, or C to develop for Android. Though there may be API restrictions, …

httpd2.2的配置文件常见设置

目录 1、启动报错:提示没有名字fqdn2、显示服务器版本信息3、修改监听的IP和Port3、持久连接4 、MPM( Multi-Processing Module )多路处理模块5 、DSO:Dynamic Shared Object6 、定义Main server (主站点) …

leetcode 149. 直线上最多的点数

题目 给你一个数组 points ,其中 points[i] [xi, yi] 表示 X-Y 平面上的一个点。求最多有多少个点在同一条直线上。 示例 1: 输入:points [[1,1],[2,2],[3,3]] 输出:3 示例 2: 输入:points [[1,1],[3,…

solidity开发以太坊代币智能合约

智能合约开发是以太坊编程的核心之一,而代币是区块链应用的关键环节,下面我们来用solidity语言开发一个代币合约的实例,希望对大家有帮助。 以太坊的应用被称为去中心化应用(DApp),DApp的开发主要包括两大部…

2019大数据课程_根据数据,2019年最佳免费在线课程

2019大数据课程As we do each year, Class Central has tallied the best courses of the previous year, based on thousands of learner reviews. (Here are the rankings from 2015, 2016, 2017, and 2018.) 与我们每年一样,根据数千名学习者的评论, …

2017-12-07 socket 读取问题

1.用socke阻塞方式读取服务端发送的数据时会出现读取一直阻塞的情况,如果设置了超时时间会在超时时间后读取到数据: 原因:在不确定服务器会不会发送 socket发送的数据不会返回null 或者-1 所以用常规的判断方法是不行的。 解决办法有两个:1 …

静态代理设计与动态代理设计

静态代理设计模式 代理设计模式最本质的特质:一个真实业务主题只完成核心操作,而所有与之辅助的功能都由代理类来完成。 例如,在进行数据库更新的过程之中,事务处理必须起作用,所以此时就可以编写代理设计模式来完成。…

svm机器学习算法_SVM机器学习算法介绍

svm机器学习算法According to OpenCVs "Introduction to Support Vector Machines", a Support Vector Machine (SVM):根据OpenCV“支持向量机简介”,支持向量机(SVM): ...is a discriminative classifier formally defined by a separating …

6.3 遍历字典

遍历所有的键—值对 遍历字典时,键—值对的返回顺序也与存储顺序不同。 6.3.2 遍历字典中的所有键 在不需要使用字典中的值时,方法keys() 很有用。 6.3.3 按顺序遍历字典中的所有键 要以特定的顺序返回元素,一种办法是在for 循环中对返回的键…

Google Guava新手教程

以下资料整理自网络 一、Google Guava入门介绍 引言 Guavaproject包括了若干被Google的 Java项目广泛依赖 的核心库,比如:集合 [collections] 、缓存 [caching] 、原生类型支持 [primitives support] 、并发库 [concurrency libraries] 、通用注解 [comm…

HTML DOM方法

querySelector() (querySelector()) The Document method querySelector() returns the first element within the document that matches the specified selector, or group of selectors. If no matches are found, null is returned.Document方法querySelector()返回文档中与…

leetcode 773. 滑动谜题

题目 在一个 2 x 3 的板上(board)有 5 块砖瓦,用数字 1~5 来表示, 以及一块空缺用 0 来表示. 一次移动定义为选择 0 与一个相邻的数字(上下左右)进行交换. 最终当板 board 的结果是 [[1,2,3],[4,5,0]] 谜板被解开。…

数据科学领域有哪些技术_领域知识在数据科学中到底有多重要?

数据科学领域有哪些技术Jeremie Harris: “In a way, it’s almost like a data scientist or a data analyst has to be like a private investigator more than just a technical person.”杰里米哈里斯(Jeremie Harris) :“ 从某种意义上说,这就像是数…

python 算术运算

1. 算术运算符与优先级 # -*- coding:utf-8 -*-# 运算符含有,-,*,/,**,//,% # ** 表示^ , 也就是次方 a 2 ** 4 print 2 ** 4 , aa 16 / 5 print 16 / 5 , aa 16.0 / 5 print 16.0 / 5 , a# 结果再进行一次floor a 16.0 // 5.0 print 16.0 // 5.0 , aa 16 // 5 print …

c语言编程时碰到取整去不了_碰到编程墙时如何解开

c语言编程时碰到取整去不了Getting stuck is part of being a programmer, no matter the level. The so-called “easy” problem is actually pretty hard. You’re not exactly sure how to move forward. What you thought would work doesn’t.无论身在何处,陷…

初创公司怎么做销售数据分析_为什么您的初创企业需要数据科学来解决这一危机...

初创公司怎么做销售数据分析The spread of coronavirus is delivering a massive blow to the global economy. The lockdown and work from home restrictions have forced thousands of startups to halt expansion plans, cancel services, and announce layoffs.冠状病毒的…