Galloping in Fast-Growth Natural Merge Sorts

IF 0.9 4区 计算机科学 Q4 COMPUTER SCIENCE, SOFTWARE ENGINEERING
Elahe Ghasemi, Vincent Jugé, Ghazal Khalighinejad, Helia Yazdanyar
{"title":"Galloping in Fast-Growth Natural Merge Sorts","authors":"Elahe Ghasemi,&nbsp;Vincent Jugé,&nbsp;Ghazal Khalighinejad,&nbsp;Helia Yazdanyar","doi":"10.1007/s00453-024-01285-6","DOIUrl":null,"url":null,"abstract":"<div><p>We study the impact of merging routines in merge-based sorting algorithms. More precisely, we focus on the <i>galloping</i> routine that TimSort uses to merge monotonic sub-arrays, hereafter called <i>runs</i>, and on the impact on the number of element comparisons performed if one uses this routine instead of a naïve merging routine. This routine was introduced in order to make TimSort more efficient on arrays with few distinct values. Alas, we prove that, although it makes TimSort sort array with two values in linear time, it does not prevent TimSort from requiring up to <span>\\(\\Theta (n \\log (n))\\)</span> element comparisons to sort arrays of length <i>n</i> with three distinct values. However, we also prove that slightly modifying TimSort ’s galloping routine results in requiring only <span>\\(\\mathcal {O}(n + n \\log (\\sigma ))\\)</span> element comparisons in the worst case, when sorting arrays of length <i>n</i> with <span>\\(\\sigma \\)</span> distinct values. We do so by focusing on the notion of <i>dual runs</i>, which was introduced in the 1990s, and on the associated <i>dual run-length entropy</i>. This notion is both related to the number of distinct values and to the number of runs in an array, which came with its own <i>run-length entropy</i> that was used to explain TimSort ’s otherwise “supernatural” efficiency. We also introduce new notions of <i>fast-</i> and <i>middle-growth</i> for natural merge sorts (i.e., algorithms based on merging runs), which are found in several sorting algorithms similar to TimSort. We prove that algorithms with the fast- or middle-growth property, provided that they use our variant of TimSort ’s galloping routine for merging runs, are as efficient as possible at sorting arrays with low run-induced or dual-run-induced complexities.\n</p></div>","PeriodicalId":50824,"journal":{"name":"Algorithmica","volume":"87 2","pages":"242 - 291"},"PeriodicalIF":0.9000,"publicationDate":"2024-12-09","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"0","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"Algorithmica","FirstCategoryId":"94","ListUrlMain":"https://link.springer.com/article/10.1007/s00453-024-01285-6","RegionNum":4,"RegionCategory":"计算机科学","ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"Q4","JCRName":"COMPUTER SCIENCE, SOFTWARE ENGINEERING","Score":null,"Total":0}
引用次数: 0

Abstract

We study the impact of merging routines in merge-based sorting algorithms. More precisely, we focus on the galloping routine that TimSort uses to merge monotonic sub-arrays, hereafter called runs, and on the impact on the number of element comparisons performed if one uses this routine instead of a naïve merging routine. This routine was introduced in order to make TimSort more efficient on arrays with few distinct values. Alas, we prove that, although it makes TimSort sort array with two values in linear time, it does not prevent TimSort from requiring up to \(\Theta (n \log (n))\) element comparisons to sort arrays of length n with three distinct values. However, we also prove that slightly modifying TimSort ’s galloping routine results in requiring only \(\mathcal {O}(n + n \log (\sigma ))\) element comparisons in the worst case, when sorting arrays of length n with \(\sigma \) distinct values. We do so by focusing on the notion of dual runs, which was introduced in the 1990s, and on the associated dual run-length entropy. This notion is both related to the number of distinct values and to the number of runs in an array, which came with its own run-length entropy that was used to explain TimSort ’s otherwise “supernatural” efficiency. We also introduce new notions of fast- and middle-growth for natural merge sorts (i.e., algorithms based on merging runs), which are found in several sorting algorithms similar to TimSort. We prove that algorithms with the fast- or middle-growth property, provided that they use our variant of TimSort ’s galloping routine for merging runs, are as efficient as possible at sorting arrays with low run-induced or dual-run-induced complexities.

Abstract Image

在快速增长的自然合并分类中驰骋
我们研究了合并例程对基于合并的排序算法的影响。更准确地说,我们关注TimSort用于合并单调子数组的飞驰例程(以后称为运行),以及如果使用该例程而不是naïve合并例程,对执行的元素比较次数的影响。引入这个例程是为了使TimSort在具有很少不同值的数组上更有效。可惜,我们证明了,虽然它使TimSort在线性时间内对具有两个值的数组进行排序,但它并不能阻止TimSort对具有三个不同值的长度为n的数组进行排序时需要进行\(\Theta (n \log (n))\)元素比较。然而,我们也证明了稍微修改TimSort的快速例程会导致在最坏的情况下只需要\(\mathcal {O}(n + n \log (\sigma ))\)元素比较,当排序长度为n的具有\(\sigma \)个不同值的数组时。为此,我们将重点放在20世纪90年代引入的双运行概念以及相关的双运行长度熵上。这个概念既与不同值的数量有关,也与数组中的运行次数有关,这与它自己的运行长度熵有关,这被用来解释TimSort在其他方面的“超自然”效率。我们还为自然归并排序(即基于归并运行的算法)引入了快速增长和中等增长的新概念,这些概念在一些类似TimSort的排序算法中可以找到。我们证明了具有快速或中等增长特性的算法,只要它们使用我们的TimSort的奔腾例程的变体进行合并运行,就可以尽可能高效地排序具有低运行诱导或双运行诱导复杂性的数组。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
求助全文
约1分钟内获得全文 求助全文
来源期刊
Algorithmica
Algorithmica 工程技术-计算机:软件工程
CiteScore
2.80
自引率
9.10%
发文量
158
审稿时长
12 months
期刊介绍: Algorithmica is an international journal which publishes theoretical papers on algorithms that address problems arising in practical areas, and experimental papers of general appeal for practical importance or techniques. The development of algorithms is an integral part of computer science. The increasing complexity and scope of computer applications makes the design of efficient algorithms essential. Algorithmica covers algorithms in applied areas such as: VLSI, distributed computing, parallel processing, automated design, robotics, graphics, data base design, software tools, as well as algorithms in fundamental areas such as sorting, searching, data structures, computational geometry, and linear programming. In addition, the journal features two special sections: Application Experience, presenting findings obtained from applications of theoretical results to practical situations, and Problems, offering short papers presenting problems on selected topics of computer science.
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
确定
请完成安全验证×
copy
已复制链接
快去分享给好友吧!
我知道了
右上角分享
点击右上角分享
0
联系我们:info@booksci.cn Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。 Copyright © 2023 布克学术 All rights reserved.
京ICP备2023020795号-1
ghs 京公网安备 11010802042870号
Book学术文献互助
Book学术文献互助群
群 号:481959085
Book学术官方微信