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

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

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.pswp.cn/news/390602.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390602.shtml
英文地址,請注明出處:http://en.pswp.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.冠狀病毒的…