亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? s_qui.htm

?? Data Structure Ebook
?? HTM
字號:
<html>
<head>
<title>Quicksort</title>
</head>
<body bgcolor="#ffffff">

<p align=right>
<a href="s_man.htm" tppabs="http://www.ee.uwa.edu.au/~plsd210/ds/niemann/s_man.htm" target="_top"><img src="c_man.gif" tppabs="http://www.ee.uwa.edu.au/~plsd210/ds/niemann/c_man.gif" width=74 height=19 border=0></a>
</p>

<h1>Quicksort</h1>

Although the shell sort algorithm is significantly better than
insertion sort, there is still room for improvement. One of the
most popular sorting algorithms is quicksort.  Quicksort executes
in <b><i>O</i></b>(<i>n</i> lg <i>n</i>) on average, and 
<b><i>O</i></b>(<i>n</i><sup>2</sup>) in the worst-case.  However,
with proper precautions, worst-case behavior is very unlikely.
Quicksort is a non-stable sort.  It is not an in-place sort as
stack space is required.  For further reading, consult
<a href="javascript:if(confirm('http://www.amazon.com/exec/obidos/ISBN=0262031418/none01A/  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.amazon.com/exec/obidos/ISBN=0262031418/none01A/'" tppabs="http://www.amazon.com/exec/obidos/ISBN=0262031418/none01A/" target="_top">Cormen [1990]</a>.

<h2>Theory</h2>
The quicksort algorithm works by partitioning the array to be
sorted, then recursively sorting each partition.  In <i>Partition</i>
(Figure 2-3),
one of the array elements is selected as a pivot
value.  Values smaller than the pivot value are placed to the
left of the pivot, while larger values are placed to the right.
<p>
<center>
<p><a name="Fig2-3"></a>
<table border cellspacing=0 cellpadding=3>
<caption align=bottom> <h3>Figure 2-3:  Quicksort Algorithm</h3> </caption>
<tr><td>
<pre>
<b>int function</b> <i>Partition</i> (<b>Array</b> <i>A</i>, <b>int</b> <i>Lb</i>, <b>int</b> <i>Ub</i>);
  <b>begin</b>
  <b>select</b> a <i>pivot</i> from <i>A</i>[<i>Lb</i>]...<i>A</i>[<i>Ub</i>];
  <b>reorder</b> <i>A</i>[<i>Lb</i>]...<i>A</i>[<i>Ub</i>] such that:
    all values to the left of the <i>pivot</i> are &lt;= pivot
    all values to the right of the <i>pivot</i> are &gt;= pivot
  <b>return</b> <i>pivot</i> position;
  <b>end;</b>

<b>procedure</b> <i>QuickSort</i> (<b>Array</b> <i>A</i>, <b>int</b> <i>Lb</i>, <b>int</b> <i>Ub</i>);
  <b>begin</b>
  <b>if</b> <i>Lb</i> &lt; <i>Ub</i> <b>then</b>
    <i>M</i> = <i>Partition</i> (<i>A</i>, <i>Lb</i>, <i>Ub</i>);
    <i>QuickSort</i> (<i>A</i>, <i>Lb</i>, <i>M</i> - 1);
    <i>QuickSort</i> (<i>A</i>, <i>M</i> + 1, <i>Ub</i>);
  <b>end;</b>
</pre>
</table>
</center>
<p>
In Figure 2-4(a),
the pivot selected is 3.  Indices are run
starting at both ends of the array. 
One index starts on the left
and selects an element that is larger than the pivot, 
while another index starts on the right and selects an element
that is smaller than the pivot.
In this case, numbers 4 and 1 are selected.
These elements are then exchanged, as is shown in
Figure 2-4(b).
This process repeats until all elements to the left of the pivot <= the pivot,
and all elements to the right of the pivot are >= the pivot.
<i>QuickSort</i> recursively sorts the two subarrays,
resulting in the array shown in Figure 2-4(c).
<center>
<h3><a name="Fig2-4">
  <img src="s_fig24.gif" tppabs="http://www.ee.uwa.edu.au/~plsd210/ds/niemann/s_fig24.gif" vspace=5 width=319 height=242><br>
  Figure 2-4:  Quicksort Example</a>
</h3>
</center>
As the process proceeds, it may be necessary to move the pivot so
that correct ordering is maintained.  In this manner, <i>QuickSort</i>
succeeds in sorting the array.  If we're lucky the pivot selected
will be the median of all values, equally dividing the
array.  For a moment, let's assume that this is the case.  Since
the array is split in half at each step, and <i>Partition</i> must
eventually examine all <i>n</i> elements, the run time is
<b><i>O</i></b>(n lg <i>n</i>).
<p>
To find a pivot value, <i>Partition</i> could simply select the first
element (<i>A</i>[<i>Lb</i>]).  All other values would be compared to the pivot
value, and placed either to the left or right of the pivot as
appropriate.  However, there is one case that fails miserably.
Suppose the array was originally in order.  <i>Partition</i> would
always select the lowest value as a pivot and split the array
with one element in the left partition, and <i>Ub</i> - <i>Lb</i> elements in
the other.  Each recursive call to quicksort would only diminish
the size of the array to be sorted by one.  Therefore <i>n</i> recursive
calls would be required to do the sort, resulting in a 
<b><i>O</i></b>(<i>n</i><sup>2</sup>) run
time.  One solution to this problem is to randomly select an item
as a pivot.  This would make it <i>extremely</i> unlikely that
worst-case behavior would occur.

<h2>Implementation</h2>
An
<a href="javascript:if(confirm('http://www.ee.uwa.edu.au/~plsd210/ds/niemann/s_qui.txt  \n\nThis file was not retrieved by Teleport Pro, because it is linked too far away from its Starting Address. If you increase the in-domain depth setting for the Starting Address, this file will be queued for retrieval.  \n\nDo you want to open it from the server?'))window.location='http://www.ee.uwa.edu.au/~plsd210/ds/niemann/s_qui.txt'" tppabs="http://www.ee.uwa.edu.au/~plsd210/ds/niemann/s_qui.txt">ANSI-C implementation</a>
for quicksort is included.
<b>Typedef T</b> and comparison operator
<b>compGT</b> should be altered to reflect the data stored in the array.
Several enhancements have been made to the basic quicksort
algorithm:
<ul>
  <li> The center element is selected as a pivot in <b>partition</b>.  If
     the list is partially ordered, this will be a good choice.  Worst-case
     behavior occurs when the center element happens to be the
     largest or smallest element each time <b>partition</b> is invoked.
  <li> For short arrays, <b>insertSort</b> is called.  Due to recursion and
     other overhead, quicksort is not an efficient algorithm to use on
     small arrays.  Consequently, any array with fewer than 12 elements is
     sorted using an insertion sort.  The optimal cutoff value is not
     critical and varies based on the quality of generated code.
  <li> Tail recursion occurs when the last statement in a function is
     a call to the function itself.  Tail recursion may be replaced by
     iteration, resulting in a better utilization of stack space.
     This has been done with the second call to <i>QuickSort</i> in Figure 2-3.
  <li>After  an  array  is partitioned, the smallest  partition  is
     sorted first.  This results in a better utilization of stack
     space, as short partitions are quickly sorted and dispensed with.
</ul>
Also  included is an
<a href="javascript:if(confirm('http://www.ee.uwa.edu.au/~plsd210/ds/niemann/s_qsort.txt  \n\nThis file was not retrieved by Teleport Pro, because it is linked too far away from its Starting Address. If you increase the in-domain depth setting for the Starting Address, this file will be queued for retrieval.  \n\nDo you want to open it from the server?'))window.location='http://www.ee.uwa.edu.au/~plsd210/ds/niemann/s_qsort.txt'" tppabs="http://www.ee.uwa.edu.au/~plsd210/ds/niemann/s_qsort.txt">ANSI-C implementation</a>,
of <i>qsort</i>, a standard C library function usually implemented  with
quicksort.  Recursive calls were
replaced by explicit stack operations.
Table 2-1, shows timing statistics and stack utilization before and after the
enhancements were applied.

<center>
<p><a name="Tbl2-1"></a>
<table border cellspacing=0 cellpadding=3>
<caption align=bottom><h3>Table 2-1:  Effect of Enhancements on Speed and Stack Utilization</h3></caption>
<tr><th rowspan=2>count</th><th colspan=2>time (&micro;s)</th><th colspan=2>stacksize</th></tr>
<tr><th>before</th><th>after</th><th>before</th><th>after</th></tr>
<tr align=right><td>16</td><td>103</td><td>51</td><td>540</td><td>28</td></tr>
<tr align=right><td>256</td><td>1,630</td><td>911</td><td>912</td><td>112</td></tr>
<tr align=right><td>4,096</td><td>34,183</td><td>20,016</td><td>1,908</td><td>168</td></tr>
<tr align=right><td>65,536</td><td>658,003</td><td>460,737</td><td>2,436</td><td>252</td></tr>
</table>
</center>

</body>
</html>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91视视频在线观看入口直接观看www | 国产精品自产自拍| 亚洲五月六月丁香激情| 国产亚洲欧美在线| 久久久不卡网国产精品一区| 久久综合九色欧美综合狠狠| 2024国产精品| 国产精品欧美精品| 亚洲欧美一区二区三区国产精品| 亚洲欧美在线高清| 一区二区三区不卡视频在线观看| 一区二区在线观看av| 亚洲福利电影网| 一区二区三区波多野结衣在线观看| 欧美精品一区二区三区高清aⅴ | 久久综合久久鬼色| 国产日产亚洲精品系列| 亚洲国产成人一区二区三区| 亚洲品质自拍视频| 丝袜美腿高跟呻吟高潮一区| 久久av中文字幕片| 国产成人日日夜夜| 99久久精品免费看| 6080yy午夜一二三区久久| 日韩免费一区二区| 国产精品丝袜黑色高跟| 亚洲综合视频在线| 蜜桃视频一区二区三区在线观看 | 亚洲欧洲一区二区在线播放| 亚洲综合久久av| 久久精品理论片| 不卡一区二区三区四区| 欧美日韩国产综合视频在线观看 | 国产精品18久久久久久vr| 欧美中文字幕亚洲一区二区va在线 | 成人性生交大片免费看中文网站| 国产精品一区一区三区| 在线观看精品一区| 久久这里只有精品6| 国产精品久久久久久亚洲毛片| 亚洲综合色区另类av| 美脚の诱脚舐め脚责91 | 99久久精品国产麻豆演员表| 91国在线观看| 久久久精品中文字幕麻豆发布| 亚洲已满18点击进入久久| 国产一区二区三区四区五区美女| 欧洲精品中文字幕| 日韩欧美一二三四区| 亚洲视频一区二区在线观看| 久久精品国产999大香线蕉| 色综合久久久网| 日韩欧美123| 亚洲欧美另类图片小说| 久草这里只有精品视频| 在线观看不卡一区| 久久久高清一区二区三区| 亚洲电影一级黄| 国产精品亚洲专一区二区三区| 欧美日韩在线不卡| 亚洲自拍另类综合| 一本色道综合亚洲| 中文字幕一区二区三区不卡| 国产精华液一区二区三区| 91精品国产高清一区二区三区蜜臀| 亚洲欧美日韩国产一区二区三区| 国产成人精品亚洲日本在线桃色| 日韩一区二区在线看片| 日韩精品一二区| 欧美精品成人一区二区三区四区| 国产精品美女久久福利网站| 精品一区二区日韩| 欧美一区二区三区爱爱| 日韩中文欧美在线| 国产成人亚洲综合a∨婷婷图片| 日韩免费观看高清完整版| 美女在线视频一区| 日韩欧美区一区二| 久久爱www久久做| 国产亚洲欧洲一区高清在线观看| 九九精品一区二区| 亚洲精品一区二区三区99| 麻豆精品一区二区av白丝在线| 精品久久久久久久一区二区蜜臀| 国精品**一区二区三区在线蜜桃| 久久日韩精品一区二区五区| 免费不卡在线视频| 欧美亚洲日本一区| 婷婷久久综合九色综合绿巨人 | 99视频精品在线| 亚洲欧洲无码一区二区三区| 91黄色免费看| 青青国产91久久久久久| 久久久一区二区三区| 成人a免费在线看| 亚洲欧美色一区| 欧美日韩一区二区三区在线 | 欧美刺激午夜性久久久久久久 | 亚洲欧美一区二区三区国产精品| 欧美在线综合视频| 精品在线一区二区| 国产精品久久久爽爽爽麻豆色哟哟 | 成人av在线播放网址| 一级做a爱片久久| 欧美tk丨vk视频| 99国产精品视频免费观看| 午夜日韩在线电影| 中文一区一区三区高中清不卡| 欧美主播一区二区三区| 精东粉嫩av免费一区二区三区| 国产精品美女久久久久aⅴ国产馆 国产精品美女久久久久av爽李琼 国产精品美女久久久久高潮 | ...xxx性欧美| 在线不卡免费av| www.日韩大片| 老司机免费视频一区二区三区| 国产精品美女久久久久久久久 | 国产亚洲制服色| 欧美天天综合网| 成人美女在线视频| 老司机午夜精品| 亚洲国产视频a| 国产精品天天摸av网| 欧美一卡二卡三卡| 色婷婷av一区| 成人少妇影院yyyy| 韩国女主播一区二区三区| 一区二区久久久久久| 国产日韩三级在线| 欧美一区二区三区在线视频| 91免费观看在线| 成人一级片在线观看| 免费高清不卡av| 五月天亚洲婷婷| 亚洲黄网站在线观看| 日本一区二区三区视频视频| 91精品欧美福利在线观看| 99视频有精品| 9i在线看片成人免费| 日韩成人一级大片| 一区二区三区中文在线| 国产清纯白嫩初高生在线观看91| 91精品黄色片免费大全| 欧美三区在线观看| 91久久国产综合久久| av不卡在线播放| 国产成人av一区二区三区在线观看| 免费看欧美女人艹b| 婷婷激情综合网| 亚洲国产欧美在线| 一区二区三区在线视频播放| 国产精品久久夜| 国产精品久久毛片a| 国产精品乱码一区二区三区软件| 久久久久97国产精华液好用吗| 欧美tk—视频vk| 精品国产91久久久久久久妲己| 91麻豆精品久久久久蜜臀| 欧美人妖巨大在线| 欧美一级爆毛片| 日韩亚洲欧美在线| 精品久久久久av影院 | 国产成人综合亚洲网站| 国产麻豆视频精品| 国产福利一区在线| 国产乱妇无码大片在线观看| 国产精品18久久久久久久网站| 国产精品88888| 成人av午夜电影| 91丨porny丨最新| 欧美在线短视频| 51精品秘密在线观看| 日韩你懂的在线播放| 久久久亚洲精华液精华液精华液| 久久久久久一二三区| 国产精品毛片大码女人| 一区二区三区在线看| 性做久久久久久| 国产一区二区三区国产| 国产精品99久久久久久似苏梦涵 | 久久99久久精品欧美| 国产福利91精品| 色播五月激情综合网| 欧美一区二区国产| 国产精品婷婷午夜在线观看| 一区二区三区电影在线播| 麻豆精品一二三| 成人av在线播放网站| 欧美精品自拍偷拍| 国产欧美日韩另类视频免费观看| 一区二区三区视频在线看| 另类调教123区| 色综合一区二区| 亚洲精品一线二线三线无人区| 亚洲欧洲精品一区二区三区不卡 | 久久综合给合久久狠狠狠97色69| 一色桃子久久精品亚洲| 日韩福利电影在线| 91影视在线播放| 国产无遮挡一区二区三区毛片日本 | 国产精品色噜噜|