Welcome![Sign In][Sign Up]
Location:
Search - qso

Search list

[Data structsqSort

Description: 快速排序算法是基于分治策略的另一个排序算法。其基本思想是,对于输入的字数组a[p:r],按以下3个步骤进行排序: (1)分解:以a[p]为基准元素将a[p:r]划分成3段a[p:q-1],a[q]和a[q+1:r],使得a[p:q-1]中任何元素小于等于a[q],a[q+1:r],中的任何元素大于等于a[q]。下标q在划分过程中确定 (2)递归求解:通过递归调用快速排序算法,分别对a[p:q-1]和a[q+1:r]进行排序 (3)合并:在a[p:q-1]和a[q+1:r]已经排好序的情况下,不需要执行任何运算,a[p:r]就已排好序 平均算法复杂度O(nlogn)-Quick sort algorithm is based on the sub-rule strategy to another sorting algorithm. The basic idea is that the word group for the importation of a [p: r], according to the following three steps to sort: (1) Decomposition: to a [p] as the base element would be a [p: r] is divided into 3 paragraphs a [p: q-1], a [q] and a [q+ 1: r], makes a [p: q-1] of any element less than or equal to a [q], a [q+ 1: r] , any element greater than or equal to a [q]. Subscript q in the demarcation process to determine (2) Recursive Solution: recursive call through the quick sort algorithm, respectively, of a [p: q-1] and a [q+ 1: r] sort (3) the merger: the a [p: q-1] and a [q+ 1: r] has lined up sequence of circumstances, do not need to perform any computation, a [p: r] has lined up an average sequence algorithm complexity O (nlogn)
Platform: | Size: 1024 | Author: 忠波 | Hits:

CodeBus www.codebus.net