青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

posts - 297,  comments - 15,  trackbacks - 0

Radix sort is the algorithm used by the card-sorting machines you now find only in computer museums. The cards are organized into 80 columns, and in each column a hole can be punched in one of 12 places. The sorter can be mechanically "programmed" to examine a given column of each card in a deck and distribute the card into one of 12 bins depending on which place has been punched. An operator can then gather the cards bin by bin, so that cards with the first place punched are on top of cards with the second place punched, and so on.

For decimal digits, only 10 places are used in each column. (The other two places are used for encoding nonnumeric characters.) A d-digit number would then occupy a field of d columns. Since the card sorter can look at only one column at a time, the problem of sorting n cards on a d-digit number requires a sorting algorithm.

Intuitively, one might want to sort numbers on their most significant digit, sort each of the resulting bins recursively, and then combine the decks in order. Unfortunately, since the cards in 9 of the 10 bins must be put aside to sort each of the bins, this procedure generates many intermediate piles of cards that must be kept track of. (See Exercise 8.3-5.)

Radix sort solves the problem of card sorting counterintuitively by sorting on the least significant digit first. The cards are then combined into a single deck, with the cards in the 0 bin preceding the cards in the 1 bin preceding the cards in the 2 bin, and so on. Then the entire deck is sorted again on the second-least significant digit and recombined in a like manner. The process continues until the cards have been sorted on all d digits. Remarkably, at that point the cards are fully sorted on the d-digit number. Thus, only d passes through the deck are required to sort. Figure 8.3 shows how radix sort operates on a "deck" of seven 3-digit numbers.

 

Figure 8.3:
The operation of radix sort on a list of seven 3-digit numbers. The leftmost column is the input. The remaining columns show the list after successive sorts on increasingly significant digit positions. Shading indicates the digit position sorted on to produce each list from the previous one.

It is essential that the digit sorts in this algorithm be stable. The sort performed by a card sorter is stable, but the operator has to be wary about not changing the order of the cards as they come out of a bin, even though all the cards in a bin have the same digit in the chosen column.

In a typical computer, which is a sequential random-access machine, radix sort is sometimes used to sort records of information that are keyed by multiple fields. For example, we might wish to sort dates by three keys: year, month, and day. We could run a sorting algorithm with a comparison function that, given two dates, compares years, and if there is a tie, compares months, and if another tie occurs, compares days. Alternatively, we could sort the information three times with a stable sort: first on day, next on month, and finally on year.

The code for radix sort is straightforward. The following procedure assumes that each element in the n-element array A has d digits, where digit 1 is the lowest-order digit and digit d is the highest-order digit.

RADIX-SORT(A, d)
1  for i  1 to d
2     do use a stable sort to sort array A on digit i
Lemma 8.3
Start example

Given n d-digit numbers in which each digit can take on up to k possible values, RADIX-SORT correctly sorts these numbers in Θ(d(n + k)) time.

Proof The correctness of radix sort follows by induction on the column being sorted (see Exercise 8.3-3). The analysis of the running time depends on the stable sort used as the intermediate sorting algorithm. When each digit is in the range 0 to k-1 (so that it can take on k possible values), and k is not too large, counting sort is the obvious choice. Each pass over n d-digit numbers then takes time Θ(n + k). There are d passes, so the total time for radix sort is Θ(d(n + k)).

End example

When d is constant and k = O(n), radix sort runs in linear time. More generally, we have some flexibility in how to break each key into digits.

Lemma 8.4
Start example

Given n b-bit numbers and any positive integer r b, RADIX-SORT correctly sorts these numbers in Θ((b/r)(n + 2r)) time.

Proof For a value r b, we view each key as having d = b/r digits of r bits each. Each digit is an integer in the range 0 to 2r - 1, so that we can use counting sort with k = 2r - 1. (For example, we can view a 32-bit word as having 4 8-bit digits, so that b = 32, r = 8, k = 2r - 1 = 255, and d = b/r = 4.) Each pass of counting sort takes time Θ(n + k) = Θ(n + 2r) and there are d passes, for a total running time of Θ(d(n + 2r )) = Θ((b/r)(n + 2r)).

End example

 

For given values of n and b, we wish to choose the value of r, with r b, that minimizes the expression (b/r)(n + 2r). If b < lg n, then for any value of r b, we have that (n + 2r) = Θ(n). Thus, choosing r = b yields a running time of (b/b)(n + 2b) = Θ(n), which is asymptotically optimal. If b lg n, then choosing r = lg n gives the best time to within a constant factor, which we can see as follows. Choosing r = lg n yields a running time of Θ(bn/ lg n). As we increase r above lg n, the 2r term in the numerator increases faster than the r term in the denominator, and so increasing r above lg n yields a running time of Θ(bn/ lg n). If instead we were to decrease r below lg n, then the b/r term increases and the n + 2r term remains at Θ(n).

Is radix sort preferable to a comparison-based sorting algorithm, such as quick-sort? If b = O(lg n), as is often the case, and we choose r lg n, then radix sort's running time is Θ(n), which appears to be better than quicksort's average-case time of Θ(n lg n). The constant factors hidden in the Θ-notation differ, however. Although radix sort may make fewer passes than quicksort over the n keys, each pass of radix sort may take significantly longer. Which sorting algorithm is preferable depends on the characteristics of the implementations, of the underlying machine (e.g., quicksort often uses hardware caches more effectively than radix sort), and of the input data. Moreover, the version of radix sort that uses counting sort as the intermediate stable sort does not sort in place, which many of the Θ(n lg n)-time comparison sorts do. Thus, when primary memory storage is at a premium, an in-place algorithm such as quicksort may be preferable

 

 

 

posted on 2010-08-03 21:43 chatler 閱讀(941) 評論(0)  編輯 收藏 引用 所屬分類: Algorithm
<2010年11月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用鏈接

留言簿(10)

隨筆分類(307)

隨筆檔案(297)

algorithm

Books_Free_Online

C++

database

Linux

Linux shell

linux socket

misce

  • cloudward
  • 感覺這個博客還是不錯,雖然做的東西和我不大相關,覺得看看還是有好處的

network

OSS

  • Google Android
  • Android is a software stack for mobile devices that includes an operating system, middleware and key applications. This early look at the Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.
  • os161 file list

overall

搜索

  •  

最新評論

閱讀排行榜

評論排行榜

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美一区二区| 性色av香蕉一区二区| 欧美黄色免费网站| 亚洲欧洲视频在线| 亚洲精品孕妇| 欧美亚洲不卡| 久久国产毛片| 麻豆乱码国产一区二区三区| 亚洲六月丁香色婷婷综合久久| 亚洲国产女人aaa毛片在线| 欧美人与性动交cc0o| 亚洲视频在线观看视频| 亚洲一区免费看| 伊人久久大香线蕉av超碰演员| 欧美高清视频| 国产精品国产三级国产aⅴ入口 | 亚洲成色777777女色窝| 亚洲国产精品成人va在线观看| 欧美日韩一区在线视频| 久久精品视频网| 欧美成人一区二区三区在线观看| 中文一区二区| 久久精品99久久香蕉国产色戒| 亚洲精品在线二区| 亚洲在线一区二区三区| 亚洲日本在线视频观看| 国产精品99久久久久久www| 黄色一区二区在线| 亚洲精品一区在线观看香蕉| 国产在线一区二区三区四区 | 亚洲视频 欧洲视频| 韩日成人在线| 亚洲在线成人精品| 最新69国产成人精品视频免费| 亚洲一区二区三区在线观看视频 | 一本色道久久综合亚洲二区三区 | 亚洲一级免费视频| 亚洲国产1区| 亚洲欧美国产制服动漫| 日韩视频在线观看国产| 欧美在线视频免费播放| 中国亚洲黄色| 欧美成人亚洲| 美女国内精品自产拍在线播放| 国产精品卡一卡二| 99精品欧美一区二区三区综合在线| 激情久久中文字幕| 午夜精品久久久| 亚洲欧美日韩天堂| 欧美日本精品一区二区三区| 欧美18av| 亚洲国产你懂的| 久久精品国产久精国产爱| 欧美亚洲在线观看| 国产精品99免费看| 日韩视频在线一区| 亚洲美女视频网| 欧美阿v一级看视频| 欧美成人精品影院| 在线观看精品视频| 欧美在线中文字幕| 久久久久久色| 国产亚洲欧洲997久久综合| 亚洲欧美精品中文字幕在线| 性做久久久久久久免费看| 国产精品久久久久久久久久久久久久 | 一区二区91| 亚洲性色视频| 国产精品美女久久久| 亚洲一区免费视频| 久久成人综合网| 国产一区二区精品久久91| 欧美一区高清| 老鸭窝毛片一区二区三区| 伊人成人在线视频| 久久综合久久美利坚合众国| 亚洲高清av| 一区二区三区波多野结衣在线观看| 欧美日本一区| 亚洲一区在线免费观看| 欧美综合国产| 亚洲第一在线| 欧美日本三区| 亚洲愉拍自拍另类高清精品| 久久一区亚洲| 99视频精品| 国产精品永久免费在线| 性欧美video另类hd性玩具| 噜噜噜躁狠狠躁狠狠精品视频| 亚洲黑丝在线| 欧美午夜精品理论片a级按摩| 亚洲制服丝袜在线| 欧美高清免费| 午夜视频一区二区| 尤物九九久久国产精品的特点 | 欧美另类一区| 亚洲免费中文| 欧美第一黄网免费网站| 亚洲午夜久久久久久久久电影院| 国产欧美短视频| 欧美承认网站| 亚洲欧美视频一区| 亚洲电影免费观看高清| 亚洲欧美韩国| 亚洲激情中文1区| 国产精品白丝av嫩草影院| 久久大香伊蕉在人线观看热2| 亚洲国产毛片完整版| 欧美一区二区三区四区夜夜大片| 亚洲人成小说网站色在线| 国产欧美日韩一级| 欧美另类人妖| 久久视频精品在线| 亚洲一区二区综合| 亚洲久久一区| 亚洲电影激情视频网站| 久久精品视频在线播放| 中文国产一区| 亚洲电影在线播放| 国产麻豆午夜三级精品| 欧美日韩成人在线观看| 久久中文精品| 欧美中文字幕在线视频| 亚洲天堂成人| aⅴ色国产欧美| 亚洲国产精品久久精品怡红院| 久久亚洲一区二区| 久久精品国产精品| 亚洲性av在线| 亚洲深爱激情| 亚洲天堂久久| 在线视频亚洲欧美| 亚洲乱码国产乱码精品精| 在线精品视频一区二区| 国内精品久久久久久久影视麻豆| 国产精品美女久久久久aⅴ国产馆| 欧美日韩精品一区二区三区四区| 免费久久精品视频| 老司机午夜精品| 久久性色av| 麻豆精品国产91久久久久久| 久久只精品国产| 毛片基地黄久久久久久天堂| 久久视频精品在线| 老司机一区二区三区| 久久久久久婷| 免费在线日韩av| 欧美电影美腿模特1979在线看| 欧美sm视频| 欧美区一区二区三区| 欧美精品综合| 国产精品国产三级国产aⅴ9色| 国产精品久久久久久久久久ktv | 亚洲精品中文字幕在线| 亚洲精品欧美极品| 夜夜嗨一区二区| 亚洲午夜电影在线观看| 亚洲综合首页| 久久精品视频网| 久热国产精品| 欧美激情中文字幕一区二区| 亚洲国产日韩一区| 99国产精品视频免费观看| 亚洲一区二区精品在线观看| 欧美一级免费视频| 美女精品视频一区| 欧美激情一区二区三区四区| 欧美日韩一卡二卡| 国产日韩一区二区| 91久久极品少妇xxxxⅹ软件| 一本色道久久综合亚洲精品按摩 | 在线视频精品| 欧美一区二区三区视频免费| 欧美.www| 亚洲综合成人在线| 久久这里只有| 国产精品久久久久一区二区三区共| 国产一区在线看| 99视频一区二区| 久久精品人人| 亚洲日韩成人| 欧美在线亚洲综合一区| 欧美精品午夜| 国产一区再线| 亚洲男人av电影| 免费在线亚洲| 亚洲欧美日产图| 欧美国产第一页| 韩国一区二区三区在线观看| 亚洲午夜久久久| 欧美国产成人在线| 亚洲欧美日韩国产成人| 欧美大尺度在线| 国产一区二区三区在线免费观看 | 极品裸体白嫩激情啪啪国产精品| 一区二区电影免费在线观看| 看欧美日韩国产| 亚洲自拍偷拍麻豆| 欧美日韩和欧美的一区二区| 亚洲第一精品夜夜躁人人躁|