去医院检查艾滋病挂什么科| 抗结剂对人有什么伤害| 电脑pin是什么意思| 11点半是什么时辰| 面皮是什么做的| 石榴石五行属什么| 锦绣未央什么意思| 血细胞分析五分类是查什么的| 蟑螂有什么危害| quilt什么意思| 天珠有什么作用与功效| 小学生什么时候考试| 利福喷丁和利福平有什么区别| 为什么会长麦粒肿| 熊掌有什么功效与作用| 眼睛充血什么原因| met是什么意思| 汪星人什么意思| 失眠是什么引起的| 拿什么让你幸福| 1974年属虎的是什么命| 肾结石有什么症状哪里疼| 魈是什么意思| 勤对什么| 全员加速中什么时候播| 白头发缺什么微量元素| 男人蛋皮痒用什么药| 肺部有阴影一般是什么病| 口蘑是什么| 甲状腺球蛋白低是什么原因| 早晨醒来口苦是什么原因| 什么是熬夜| 鹦鹉爱吃什么| 重阳节吃什么好| 夏季有什么花| 2018年属什么生肖| 怀孕什么症状| 珍珠鸟吃什么食物| 暗里着迷什么意思| 不齿是什么意思| 咳嗽喉咙痛吃什么药| 为什么会缺铁| 心主什么| 后脑勺疼痛什么原因引起的| 什么叫息肉| 12月2日什么星座| 束脚裤配什么鞋子| 一什么枣子| 月经不来要吃什么药| 金字旁目字读什么| 摩尔是什么| 大雄宝殿供奉的是什么佛| 睡前喝蜂蜜水有什么好处| 认知什么意思| 中国最大的岛屿是什么| 缘故的故是什么意思| 上睑下垂是什么原因造成的| 重庆为什么这么热| 脸上经常长痘痘是什么原因| 纪是什么意思| 脚底板发热是什么原因| 衡水老白干是什么香型| 蛋白质用什么试剂鉴定| fvc是什么意思| 鬼什么虎| 表达什么意思| 炎症反应性细胞改变是什么意思| 兰陵为什么改名枣庄| 蓝姓是什么民族| dob是什么意思| 红旗代表什么生肖| 公开遴选公务员是什么意思| 西皮是什么皮| 浮肿是什么原因造成的| 晨起口干口苦是什么原因| 后壁和前壁有什么区别| 烫伤涂什么| 蚊子喜欢叮什么样的人| pony是什么意思| 血压高什么原因引起的| 蝎子泡酒有什么功效| 888是什么意思| 胆囊大是什么原因| 肝胃不和吃什么药| 中元节是什么| 9月25日什么星座| 缺少雌激素的女性会有什么症状| 假冒警察什么罪怎么判| 头颅mri是什么检查| 凤尾菜又叫什么菜| cafe是什么意思| 左侧后背疼是什么原因男性| 现在摆摊卖什么东西最好卖| 女生下体长什么样子| 靥什么意思| wonderflower是什么牌子| 吸渣体质是什么意思| 骨髓纤维化是什么病| 黄豆吃多了有什么坏处| 为什么子宫会下垂| 爬是什么结构| 疑神疑鬼是什么意思| 肾火吃什么药| 承上启下是什么意思| 一步两步三步四步望着天是什么歌| 麻椒和花椒有什么区别| 什么奶粉比较好| 和合是什么意思| 五行缺什么查询免费| 腹肌不对称是什么原因| 吃什么代谢快有助于减肥| 分泌物多是什么原因| 什么是射频消融术| 外阴过敏用什么药| 梦见杀蛇是什么意思| 哺乳期牙龈肿痛可以吃什么药| mcu是什么| 霸道是什么意思| 严重贫血的人吃什么补血最快| 偶尔失眠是什么原因| 愚钝是什么意思| 什么叫阴虚什么叫阳虚| 烧心反酸水吃什么药| 藏红花泡水喝有什么功效| 鼻子肿了又硬又疼是什么原因| 做梦梦见火是什么征兆| 膀胱炎吃什么药| 鸳鸯戏水是什么意思| 筋膜炎用什么药好| 头不舒服去医院挂什么科| 宫颈纳氏囊肿是什么意思严重吗| 一个月一个办念什么| 小孩手麻是什么原因| 7月31日是什么星座| 糖类抗原是检查什么的| 鸾俦是什么意思| 3月有什么节日| 查血型挂什么科| 上午十点半是什么时辰| 白菜发苦是什么原因| 倒车雷达什么牌子好| 肠息肉有什么症状| 身上长黑痣是什么原因| 伤官见官是什么意思| 独角兽是什么动物| 不思量 自难忘什么意思| 888红包代表什么意思| 音容笑貌的意思是什么| 梅子和杏有什么区别| 天秤座是什么星座| 所向披靡什么意思| 羽军念什么| 女人肾阴虚吃什么药| 精血亏虚吃什么中成药| 平起平坐是什么动物| 长期喝枸杞水有什么好处和坏处| 梦见小男孩拉屎是什么意思| 周深为什么是女声| 老花镜什么品牌好| 什么的孙悟空| 观音得道日是什么时候| 西瓜为什么叫西瓜| 根源是什么意思| 什么是汛期| 雪白的什么| 痤疮是什么样子的| 散粉和粉饼有什么区别| 何方神圣是什么意思| 家里狗死了预示着什么| 壁虎进家里预示什么| 佛口蛇心是什么生肖| 小白兔是什么意思| 云翳是什么意思| 挪威用什么货币| 泻火是什么意思| 孕妇贫血吃什么好| 腹膜转移是什么意思| 脑梗吃什么药可以恢复的快| 鼻子上长红疙瘩是什么原因| 尿频尿急是什么原因| 什么不什么干| 乳腺癌多发于什么年龄| boy是什么牌子| 梦见修路什么意思| 右眼皮上长痣代表什么| 宝宝尿少是什么原因| 汕头有什么好玩的地方| 大什么大| 冬眠灵是什么药| 桂圆跟龙眼有什么区别| 你最想做什么| 山洪是什么意思| 关节炎用什么药最好| 家里来猫是什么征兆| 冲牛煞西是什么意思| 肺和大肠相表里是什么意思| 族谱是什么意思| gv是什么意思| h2o是什么意思| 周末大小休是什么意思| 五大发展理念是什么| 血小板减少是什么原因| 尿里红细胞高什么原因| 强磁对人体有什么危害| 身上痒但是什么都没有| 西米是什么做的| 毓字五行属什么| 什么叫奢侈| 晚上左眼皮跳预示什么| 次氯酸钠是什么| 吃什么有助于排便| 有机会是什么意思| 全麻后需要注意什么| 911是什么电话| 尿糖1十是什么意思| 履什么意思| 79年属什么的生肖| 寅是什么意思| 艺人是什么意思| 初恋什么意思| 缓刑什么意思| 什么水果含钾高| 结肠和直肠有什么区别| 发烧是什么症状| 居住证是什么| 锹形虫吃什么| 半身不遂的前兆是什么症状| 小孩子发烧是什么原因引起的| 吃什么补钾最快最好| emr是什么意思| 脾湿吃什么中成药| 甲亢吃什么好| 偏头疼是什么原因引起| 受用是什么意思| 如果怀孕了会有什么预兆| 一饿就心慌是什么原因引起的| 三个贝念什么| 吃秋葵有什么好处| 女性脱发严重是什么原因引起的| 什么是部首| 尿痛挂什么科| 花青素是什么颜色| 繁花似锦是什么意思| 梦见自己儿子死了是什么意思| 6月24日什么星座| 胃炎胃溃疡吃什么药| 下家是什么意思| 单脐动脉对胎儿有什么影响| 水仙茶适合什么人喝| 黄粱是什么意思| h是什么意思| 什么地站着| 1898年属什么生肖| 女人被操是什么感觉| 淋是什么意思| 7月7日什么星座| 紫茉莉什么时候开花| 记性不好吃什么药| 麝香对孕妇有什么危害性| 翡翠和玉石有什么区别| 上海什么房子不限购| s和m是什么意思啊| 驴板肠是什么部位| 狗屎运是什么意思| 百度

取消二手车限迁政策落地情况不乐观 三部委将督查

百度 他们原本大多是特朗普的支持者,让他们去向特朗普讨公道吧。

In computer science, partial sorting is a relaxed variant of the sorting problem. Total sorting is the problem of returning a list of items such that its elements all appear in order, while partial sorting is returning a list of the k smallest (or k largest) elements in order. The other elements (above the k smallest ones) may also be sorted, as in an in-place partial sort, or may be discarded, which is common in streaming partial sorts. A common practical example of partial sorting is computing the "Top 100" of some list.

In terms of indices, in a partially sorted list, for every index i from 1 to k, the i-th element is in the same place as it would be in the fully sorted list: element i of the partially sorted list contains order statistic i of the input list.

Offline problems

edit

Heap-based solution

edit

Heaps admit a simple single-pass partial sort when k is fixed: insert the first k elements of the input into a max-heap. Then make one pass over the remaining elements, add each to the heap in turn, and remove the largest element. Each insertion operation takes O(log k) time, resulting in O(n log k) time overall; this "partial heapsort" algorithm is practical for small values of k and in online settings.[1] An "online heapselect" algorithm described below, based on a min-heap, takes O(n + k log n).[1]

Solution by partitioning selection

edit

A further relaxation requiring only a list of the k smallest elements, but without requiring that these be ordered, makes the problem equivalent to partition-based selection; the original partial sorting problem can be solved by such a selection algorithm to obtain an array where the first k elements are the k smallest, and sorting these, at a total cost of O(n + k log k) operations. A popular choice to implement this algorithm scheme is to combine quickselect and quicksort; the result is sometimes called "quickselsort".[1]

Common in current (as of 2022) C++ STL implementations is a pass of heapselect for a list of k elements, followed by a heapsort for the final result.[2]

Specialised sorting algorithms

edit

More efficient than the aforementioned are specialized partial sorting algorithms based on mergesort and quicksort. In the quicksort variant, there is no need to recursively sort partitions which only contain elements that would fall after the k'th place in the final sorted array (starting from the "left" boundary). Thus, if the pivot falls in position k or later, we recurse only on the left partition:[3]

function partial_quicksort(A, i, j, k) is
    if i < j then
        p ← pivot(A, i, j)
        p ← partition(A, i, j, p)
        partial_quicksort(A, i, p-1, k)
        if p < k-1 then
            partial_quicksort(A, p+1, j, k)

The resulting algorithm is called partial quicksort and requires an expected time of only O(n + k log k), and is quite efficient in practice, especially if a selection sort is used as a base case when k becomes small relative to n. However, the worst-case time complexity is still very bad, in the case of a bad pivot selection. Pivot selection along the lines of the worst-case linear time selection algorithm (see Quicksort §?Choice of pivot) could be used to get better worst-case performance. Partial quicksort, quickselect (including the multiple variant), and quicksort can all be generalized into what is known as a chunksort.[1]

Incremental sorting

edit

Incremental sorting is a version of the partial sorting problem where the input is given up front but k is unknown: given a k-sorted array, it should be possible to extend the partially sorted part so that the array becomes (k+1)-sorted.[4]

Heaps lead to an O(n + k log n) "online heapselect" solution to incremental partial sorting: first "heapify", in linear time, the complete input array to produce a min-heap. Then extract the minimum of the heap k times.[1]

A different incremental sort can be obtained by modifying quickselect. The version due to Paredes and Navarro maintains a stack of pivots across calls, so that incremental sorting can be accomplished by repeatedly requesting the smallest item of an array A from the following algorithm:[4]

Algorithm IQS(A?: array, i?: integer, S?: stack) returns the i'th smallest element in A

  • If i = top(S):
    • Pop S
    • Return A[i]
  • Let pivot ← random [i, top(S))
  • Update pivot ← partition(A[i?: top(S)), A[pivot])
  • Push pivot onto S
  • Return IQS(A, i, S)

The stack S is initialized to contain only the length n of A. k-sorting the array is done by calling IQS(A, i, S) for i = 0, 1, 2, ...; this sequence of calls has average-case complexity O(n + k log k), which is asymptotically equivalent to O(n + k log n). The worst-case time is quadratic, but this can be fixed by replacing the random pivot selection by the median of medians algorithm.[4]

Language/library support

edit

See also

edit

References

edit
  1. ^ a b c d e Conrado Martínez (2004). On partial sorting (PDF). 10th Seminar on the Analysis of Algorithms.
  2. ^ "std::partial_sort". en.cppreference.com.
  3. ^ Martínez, Conrado (2004). Partial quicksort (PDF). Proc. 6th ACM-SIAM Workshop on Algorithm Engineering and Experiments and 1st ACM-SIAM Workshop on Analytic Algorithmics and Combinatorics.
  4. ^ a b c Paredes, Rodrigo; Navarro, Gonzalo (2006). "Optimal Incremental Sorting". Proc. Eighth Workshop on Algorithm Engineering and Experiments (ALENEX). pp.?171–182. CiteSeerX?10.1.1.218.4119. doi:10.1137/1.9781611972863.16. ISBN?978-1-61197-286-3.
edit
东宫是什么意思 现在有什么赚钱的路子 头晕目眩是什么病的征兆 什么情况下需要做造影 用什么方法可以戒酒
有氧运动和无氧运动有什么区别 大便带血是什么原因男 梅毒检查挂什么科 叶芽是什么 道观是什么意思
大姨妈来了可以吃什么水果 邓超的公司叫什么名字 体内湿气重吃什么食物 马桶对着卫生间门有什么不好 周岁和虚岁是什么意思
唐僧的袈裟叫什么 什么得什么造句 磨豆浆是什么意思 出车前检查的目的是什么 合卺是什么意思
风寒感冒喉咙痛吃什么药hcv9jop3ns8r.cn 百步穿杨是什么生肖qingzhougame.com 螳螂喜欢吃什么hcv7jop4ns6r.cn 60是什么意思hcv8jop2ns7r.cn 大拇指旁边是什么指hcv9jop2ns8r.cn
丁香花长什么样hcv9jop0ns7r.cn 老三篇是什么意思hcv9jop2ns9r.cn 兰州有什么好吃的hcv7jop5ns6r.cn 小孩子上户口需要什么证件hcv8jop8ns9r.cn 图灵是什么意思hcv7jop9ns5r.cn
翊读什么hcv9jop4ns3r.cn 信女是什么意思hcv9jop5ns0r.cn 有什么副作用zsyouku.com 小孩铅过高有什么症状hcv9jop7ns1r.cn 内痔疮有什么症状hcv7jop5ns4r.cn
口腔溃疡吃什么水果好得快hcv9jop2ns0r.cn 押韵什么意思hcv9jop4ns4r.cn 荻是什么意思hcv9jop3ns9r.cn 独在异乡为异客的异是什么意思weuuu.com 丹参滴丸和丹参片有什么区别ff14chat.com
百度