白帆是什么| 什么一什么什么成语| 准生证什么时候办| 木瓜不能和什么一起吃| 女生考什么证书最实用| 拉k是什么意思| 尿中泡沫多是什么原因| 撰文是什么意思| 补休是什么意思| 病毒感冒吃什么消炎药| 什么书好看| 肩周炎是什么引起的| 婴儿反复发烧是什么原因| 跖围是什么意思| 外阴瘙痒用什么药好| 杏色搭配什么颜色好看| 推拿是什么意思| 女人吃知了有什么好处| 棕榈油是什么油| 调戏什么意思| 夏天吃什么水果最好| 301医院院长什么级别| 老年人骨质疏松吃什么钙片好| 二郎腿为什么叫二郎腿| 金童玉女是什么意思| 经常脚抽筋是什么原因| 女生经常手淫有什么危害| 骨刺吃什么药| 7.11是什么星座| 刘诗诗是什么样的人| 三个犬念什么字| 孕妇吐得厉害有什么办法解决| 糖尿病人适合喝什么茶| 眼睛痒什么原因| 漫山遍野是什么意思| 巫婆是什么意思| 八月出生的是什么星座| 喝牛奶不能和什么一起吃| 仙草粉是什么做的| 睡觉梦到蛇是什么意思| 欧诗漫是个什么档次| 五月26日是什么星座| 脸色暗沉发黑是什么原因| 白细胞酯酶弱阳性什么意思| 安宫牛黄丸治什么病| 子宫出血什么原因| 安全期是指什么时间| 维生素c的作用是什么| 肾阴虚吃什么药最好| 做什么检查确诊是白塞| 灰度是什么意思| 自强不息的息是什么意思| 流光是什么意思| 四月十六日是什么星座| 排骨炖什么最好吃| 经常喝苏打水有什么好处和坏处| 牛骨煲什么汤对儿童好| 女人吃莲藕有什么好处| 为什么叫韩国人棒子| 骨折吃什么恢复得快| 做梦梦到猪是什么意思| 血糖高什么东西不能吃| 下午4点到5点是什么时辰| 不可什么什么| 便秘用什么药好| 小孩摇头是什么原因| 决堤是什么意思| 降结肠在什么位置| 奔富红酒属于什么档次| 检查全身挂什么科| 36d是什么意思| 绿豆吃多了有什么坏处| 异常白细胞形态检查是查什么病| 脚突然抽筋是什么原因| 伤寒是什么意思| 仓鼠和老鼠有什么区别| 高考是什么| 引体向上有什么好处| 甲状腺1度肿大是什么意思| 榨菜是什么菜做的| 进字五行属什么| 98年属相是什么| 宝宝辅食虾和什么搭配| 你有什么| 轮状病毒吃什么药| 怀孕甲减对孩子有什么影响| 太阳代表什么数字| 2008年是什么年| 稀饭配什么菜好吃| 可以组什么词语| 急性青光眼是什么症状| 是什么歌曲| 太平鸟属于什么档次| 为什么生理期过后最容易掉秤| 什么是gmp| 射手男和什么座最配对| 什么时候放开二胎| 4.26是什么星座| 拉肚子吃什么菜| 什么是直肠炎| 珠地棉是什么面料| yjs是什么意思| 苹果手机为什么充不进去电| 杭州菜属于什么菜系| 月经腰疼是什么原因引起的| 病危通知书意味着什么| 婴儿什么时候开始说话| 为什么狐臭女很漂亮| 百忧解是什么药| 尽收眼底是什么意思| 法国货币叫什么| 市委副秘书长什么级别| 牙龈疼是什么原因| 中暑吃什么药| 梦见假牙掉了是什么意思| 离苦得乐什么意思| 三角巾是什么| 有机和无机是什么意思| 尿血是什么病| 黄连治什么病最好| 肝实质回声细密是什么意思| 鳑鲏吃什么| 种牙是什么意思| 奔波是什么意思| 出脚汗是什么原因| 为什么闰月| 放低姿态是什么意思| 解禁是什么意思| 羽毛球拍磅数是什么意思| 泳帽什么材质的好| 生肖鼠和什么生肖相冲| 吃什么不上火| 1999年出生属什么生肖| 病案首页是什么| carrera手表什么牌子| 糖类抗原125高是什么意思| 脊髓灰质炎是什么病| 过氧化氢弱阳性什么意思| 蛋白质是什么食物| 利妥昔单抗是什么药| 抗体高是什么意思| 梦见鱼是什么预兆| 桂字五行属什么| 什么目什么身| 月亮象征着什么| 两个吉念什么| 热疹用什么药膏最好| 情志是什么意思| 梅毒会通过什么传染| 好无奈是什么意思| 什么是拘役| 金匮是什么意思| 肺部增殖灶是什么意思| 头上的旋有什么说法| 安宫牛黄丸为什么那么贵| 人流后吃什么好| 盲肠憩室是什么意思| verde是什么颜色| 有什么故事| 风是什么| ph是什么意思| 咳黄痰吃什么药| 酱油是什么做的| 艾草长什么样| 什么水解酒| 宫保鸡丁是什么菜系| 水命是什么意思| 红豆和什么搭配最好| 布五行属什么| normal是什么意思| 启明星是什么意思| 女性排卵期有什么表现| 结膜水肿用什么眼药水| 哮喘病有什么症状| 持续低烧不退是什么原因| 腮腺炎吃什么消炎药| 儿童乘坐高铁需要什么证件| 瞳距是什么| 牙龈肿痛吃什么中成药| style是什么意思| o和b型生的孩子是什么血型| 开车不能穿什么鞋| pgr是什么意思| 银行卡销户是什么意思| 对口升学什么意思| 拉开帷幕是什么意思| 马齿苋长什么样子| 什么地坐着| 很的右边读什么| 黄瓜敷脸有什么功效| 夏天什么面料最凉快| 肚子冰凉是什么原因| 美甲什么颜色显手白| 日本的町是什么意思| 贫嘴是什么意思| 外阴瘙痒用什么| 人参果什么季节成熟| 穿什么颜色显白| 苹果补充什么维生素| gv是什么| gd是什么意思| 宫颈ca什么意思| 你想要什么我都会给| 人为什么要吃肉| pe是什么意思| 胃恶心想吐是什么原因| 右肺中叶索条什么意思| 为什么会长脂肪瘤| 戾什么意思| 紧急避孕药什么时候吃最有效| 梦到小孩子是什么意思| 婴儿坐飞机需要什么证件| 肠道紊乱的症状是什么| 备孕怀男孩做什么准备| 1957年发生了什么| 肝胆相照什么意思| 梦到头发白了是什么意思| 黄瓜炒什么菜好吃| 眼睛视力模糊是什么原因| 猪身上红疙瘩用什么药| 三番四次是什么生肖| 腿痛去医院挂什么科| 杀子痣是什么意思| 胡塞武装是什么| 什么水果对肝有好处| 甲亢是什么| 脸上长痘痘用什么药膏效果好| 靶向药有什么副作用| 哪吒妈妈叫什么名字| 什么是木薯粉| 花椒有什么作用| 高锰酸钾治疗男性什么病| 历经是什么意思| 乳头突然疼痛什么原因| 人体七大营养素是什么| 为什么空腹喝牛奶会拉肚子| 什么是乳腺增生| 为什么二楼比三楼好| 八卦是什么生肖| 头疼流鼻血是什么原因| 1288是什么意思| grace是什么意思| 九出十三归指什么生肖| 什么是性压抑| 什么叫做原发性高血压| 维酶素片搭配什么药治萎缩性胃炎| shuuemura是什么牌子| ais是什么意思| 木字旁的字有什么| 亚麻籽油有什么功效| 冰淇淋是什么做的| 吃白饭是什么意思| 左眼跳女人是什么预兆| 猫能看到什么颜色| 痔疮吃什么药最好| 再者是什么意思| 强势的人有什么特点| 妊娠期是指什么时候| 什么是胰腺炎| 不典型增生是什么意思| 最难做的饭是什么| 油皮适合用什么护肤品| 小宇宙是什么意思| 52什么意思| 百度Jump to content

胃炎吃什么

From Wikipedia, the free encyclopedia
(Redirected from Postman sort)
Bucket sort
ClassSorting algorithm
Data structureArray
Worst-case performance
Average performance, where k is the number of buckets. .
Worst-case space complexity
Elements are distributed among bins
Then, elements are sorted within each bin
百度 与上述相比,绿驰汽车则是个特立独行者,是首个全球化集成创新的先行者。

Bucket sort, or bin sort, is a sorting algorithm that works by distributing the elements of an array into a number of buckets. Each bucket is then sorted individually, either using a different sorting algorithm, or by recursively applying the bucket sorting algorithm. It is a distribution sort, a generalization of pigeonhole sort that allows multiple keys per bucket, and is a cousin of radix sort in the most-to-least significant digit flavor. Bucket sort can be implemented with comparisons and therefore can also be considered a comparison sort algorithm. The computational complexity depends on the algorithm used to sort each bucket, the number of buckets to use, and whether the input is uniformly distributed.

Bucket sort works as follows:

  1. Set up an array of initially empty "buckets".
  2. Scatter: Go over the original array, putting each object in its bucket.
  3. Sort each non-empty bucket.
  4. Gather: Visit the buckets in order and put all elements back into the original array.

Pseudocode

[edit]
function bucketSort(array, k) is
    buckets ← new array of k empty lists
    M ← 1 + the maximum key value in the array
    for i = 0 to length(array) do
        insert array[i] into buckets[floor(k × array[i] / M)]
    for i = 0 to k do 
        nextSort(buckets[i])
    return the concatenation of buckets[0], ...., buckets[k]

Let array denote the array to be sorted and k denote the number of buckets to use. One can compute the maximum key value in linear time by iterating over all the keys once. The floor function must be used to convert a floating number to an integer ( and possibly casting of datatypes too ). The function nextSort is a sorting function used to sort each bucket. Conventionally, insertion sort is used due to its relatively high performance with small numbers of elements, but other algorithms could be used as well, such as selection sort or merge sort. Using bucketSort itself as nextSort produces a relative of radix sort; in particular, the case n = 2 corresponds to quicksort (although potentially with poor pivot choices).

Analysis

[edit]

Worst-case analysis

[edit]

When the input contains several keys that are close to each other (clustering), those elements are likely to be placed in the same bucket, which results in some buckets containing more elements than average. The worst-case scenario occurs when all the elements are placed in a single bucket. The overall performance would then be dominated by the algorithm used to sort each bucket, for example insertion sort or comparison sort algorithms, such as merge sort.

Average-case analysis

[edit]

Consider the case that the input is uniformly distributed. The first step, which is initialize the buckets and find the maximum key value in the array, can be done in time. If division and multiplication can be done in constant time, then scattering each element to its bucket also costs . Assume insertion sort is used to sort each bucket, then the third step costs , where is the length of the bucket indexed . Since we are concerning the average time, the expectation has to be evaluated instead. Let be the random variable that is if element is placed in bucket , and otherwise. We have . Therefore,

The last line separates the summation into the case and the case . Since the chance of an object distributed to bucket is , is 1 with probability and 0 otherwise.

With the summation, it would be

Finally, the complexity would be .

The last step of bucket sort, which is concatenating all the sorted objects in each bucket, requires time. Therefore, the total complexity is . Note that if k is chosen to be , then bucket sort runs in average time, given a uniformly distributed input.[1]

Optimizations

[edit]

A common optimization is to put the unsorted elements of the buckets back in the original array first, then run insertion sort over the complete array; because insertion sort's runtime is based on how far each element is from its final position, the number of comparisons remains relatively small, and the memory hierarchy is better exploited by storing the list contiguously in memory.[2]

If the input distribution is known or can be estimated, buckets can often be chosen which contain constant density (rather than merely having constant size). This allows average time complexity even without uniformly distributed input.

Variants

[edit]

Generic bucket sort

[edit]

The most common variant of bucket sort operates on a list of n numeric inputs between zero and some maximum value M and divides the value range into b buckets each of size M/b. If each bucket is sorted using insertion sort, the sort can be shown to run in expected linear time (where the average is taken over all possible inputs).[3] However, the performance of this sort degrades with clustering; if many values occur close together, they will all fall into a single bucket and be sorted slowly. This performance degradation is avoided in the original bucket sort algorithm by assuming that the input is generated by a random process that distributes elements uniformly over the interval [0,1).[1]

ProxmapSort

[edit]

Similar to generic bucket sort as described above, ProxmapSort works by dividing an array of keys into subarrays via the use of a "map key" function that preserves a partial ordering on the keys; as each key is added to its subarray, insertion sort is used to keep that subarray sorted, resulting in the entire array being in sorted order when ProxmapSort completes. ProxmapSort differs from bucket sorts in its use of the map key to place the data approximately where it belongs in sorted order, producing a "proxmap" — a proximity mapping — of the keys.

Histogram sort

[edit]

Another variant of bucket sort known as histogram sort or counting sort adds an initial pass that counts the number of elements that will fall into each bucket using a count array.[4] Using this information, the array values can be arranged into a sequence of buckets in-place by a sequence of exchanges, leaving no space overhead for bucket storage.[failed verification]

Postman's sort

[edit]

The Postman's sort is a variant of bucket sort that takes advantage of a hierarchical structure of elements, typically described by a set of attributes. This is the algorithm used by letter-sorting machines in post offices: mail is sorted first between domestic and international; then by state, province or territory; then by destination post office; then by routes, etc. Since keys are not compared against each other, sorting time is O(cn), where c depends on the size of the key and number of buckets. This is similar to a radix sort that works "top down," or "most significant digit first."[5]

Shuffle sort

[edit]

The shuffle sort[6] is a variant of bucket sort that begins by removing the first 1/8 of the n items to be sorted, sorts them recursively, and puts them in an array. This creates n/8 "buckets" to which the remaining 7/8 of the items are distributed. Each "bucket" is then sorted, and the "buckets" are concatenated into a sorted array.

Comparison with other sorting algorithms

[edit]

Bucket sort can be seen as a generalization of counting sort; in fact, if each bucket has size 1 then bucket sort degenerates to counting sort. The variable bucket size of bucket sort allows it to use O(n) memory instead of O(M) memory, where M is the number of distinct values; in exchange, it gives up counting sort's O(n + M) worst-case behavior.

Bucket sort with two buckets is effectively a version of quicksort where the pivot value is always selected to be the middle value of the value range. While this choice is effective for uniformly distributed inputs, other means of choosing the pivot in quicksort such as randomly selected pivots make it more resistant to clustering in the input distribution.

The n-way mergesort algorithm also begins by distributing the list into n sublists and sorting each one; however, the sublists created by mergesort have overlapping value ranges and so cannot be recombined by simple concatenation as in bucket sort. Instead, they must be interleaved by a merge algorithm. However, this added expense is counterbalanced by the simpler scatter phase and the ability to ensure that each sublist is the same size, providing a good worst-case time bound.

Top-down radix sort can be seen as a special case of bucket sort where both the range of values and the number of buckets is constrained to be a power of two. Consequently, each bucket's size is also a power of two, and the procedure can be applied recursively. This approach can accelerate the scatter phase, since we only need to examine a prefix of the bit representation of each element to determine its bucket.

References

[edit]
  1. ^ a b Thomas H. Cormen; Charles E. Leiserson; Ronald L. Rivest & Clifford Stein. Introduction to Algorithms. Bucket sort runs in linear time on the average. Like counting sort, bucket sort is fast because it assumes something about the input. Whereas counting sort assumes that the input consists of integers in a small range, bucket sort assumes that the input is generated by a random process that distributes elements uniformly over the interval [0,1). The idea of bucket sort is to divide the interval [0, 1) into n equal-sized subintervals, or buckets, and then distribute the n input numbers into the buckets. Since the inputs are uniformly distributed over [0, 1), we don't expect many numbers to fall into each bucket. To produce the output, we simply sort the numbers in each bucket and then go through the buckets in order, listing the elements in each.
  2. ^ Corwin, E. and Logar, A. "Sorting in linear time — variations on the bucket sort". Journal of Computing Sciences in Colleges, 20, 1, pp.197–202. October 2004.
  3. ^ Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms, Second Edition. MIT Press and McGraw-Hill, 2001. ISBN 0-262-03293-7. Section 8.4: Bucket sort, pp.174–177.
  4. ^ NIST's Dictionary of Algorithms and Data Structures: histogram sort
  5. ^ "Robert Ramey Software Development".
  6. ^ A revolutionary new sort from John Cohen Nov 26, 1997
[edit]
爱是什么歌曲 皮肤发黑是什么原因引起的 甲状腺4级是什么意思 血糖高吃什么主食好 小孩放屁很臭是什么原因
陆勤合格什么意思 x射线是什么 什么飞机 男生为什么会勃起 儿童吃什么钙片补钙效果好
水痘不能吃什么食物 吃什么降血脂最好 身上发热是什么原因 欢愉是什么意思 退烧吃什么药好
随笔是什么意思 作践自己是什么意思 男性尿道炎是什么原因引起的 什么相马 黄酒是什么
赤道2什么时候上映hcv8jop9ns0r.cn 越南有什么特产hcv9jop5ns3r.cn 阮小五的绰号是什么hcv8jop8ns2r.cn 什么命要承受丧子之痛hcv7jop5ns1r.cn 周岁和虚岁是什么意思creativexi.com
脸上长痣是什么原因造成的hcv8jop4ns0r.cn 为什么叫韩国人棒子gysmod.com 段子是什么意思cj623037.com 25是什么生肖hcv9jop7ns3r.cn 钙果是什么水果hcv9jop2ns9r.cn
12月9号是什么星座hcv8jop0ns5r.cn 蝙蝠吃什么食物hcv8jop7ns0r.cn 大便遇水就散什么原因hcv8jop3ns7r.cn 阳虚水泛是什么症状hcv8jop1ns2r.cn 左侧卵巢内无回声是什么意思hcv9jop4ns3r.cn
肚脐周围疼痛是什么原因hcv9jop8ns3r.cn 乌纱帽是什么意思hcv7jop9ns3r.cn 杨颖原名叫什么hcv7jop5ns0r.cn 最贵的玉是什么玉hcv8jop9ns7r.cn 什么克水cl108k.com
百度