Timsort
https://archive.codeplex.com/?p=timsort4net#117964
download archive https://codeplexarchive.blob.core.windows.net/archive/projects/timsort4net/timsort4net.zip
Project Description
TimSort is relatively new sorting algorithm invented by Tim Peters in 2002, which is a hybrid of adaptive MergeSort and InsertionSort. It is not worse than QuickSort which modified version is used as default sorting algorithm in .NET. TimSort's average case performance is O(n log n) (same as QuickSort) but both best case and worst case performances are bettern then QuickSort: O(n) and O(n log n) respectively (QuickSort is O(n log n) and O(n^2)).
This implementation is a C# translation of Josh Bloch's Java implementation of TimSort.
Wikipedia: http://en.wikipedia.org/wiki/Timsort
Josh Bloch's Java implementation: http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/main/java/util/TimSort.java?view=co
TimSort takes advantage of two facts:
data we sort is often already partially sorted
comparison might be expensive (complex Compare method) while swapping elements is cheap (swapping pointers)
When comparison gets slower (for example, comparing complex objects) TimSort increases its advantage over QuickSort.
Array of 5368709 items, quick compare function: (actually: int.CompareTo(int))
Random data
Builtin: 1859.4927ms
TimSort: 1773.2582ms
Generally ascending data (80% chance that next item is greater than previous one)
Builtin: 1166.6400ms;
TimSort: 247.1780ms
Generally descending data (80% chance that next item is smaller than previous one)
Builtin: 1190.5521ms
TimSort: 571.7132ms
NOTE: TimSort's performance is the same for random data, but is significantly better for already ordered data.
Array of 536870 items, quite slow compare function (I actually added Thread.Sleep(0) to it):
Random data
Builtin: 6117.1032ms
TimSort: 4578.1129ms
Generally ascending data (80% chance that next item is greater than previous one)
Builtin: 5323.7977ms
TimSort: 841.0910ms
Generally descending data (80% chance that next item is smaller than previous one)
Builtin: 5321.9103ms
TimSort: 1094.5267ms
NOTE: TimSort's performance is better than QuickSort's when compare function is slow, even for random data.
Python's listobject.c – the C implementation of Timsort used in CPython
https://github.com/python/cpython/blob/master/Objects/listobject.c
https://sikasjc.github.io/2018/07/25/timsort/
http://hg.savannah.gnu.org/hgweb/octave/file/0486a29d780f/liboctave/util/oct-sort.cc
https://csharp.hotexamples.com/examples/-/List/TimSort/php-list-timsort-method-examples.html
Timsort的更多相关文章
- 简易版的TimSort排序算法
欢迎探讨,如有错误敬请指正 如需转载,请注明出处http://www.cnblogs.com/nullzx/ 1. 简易版本TimSort排序算法原理与实现 TimSort排序算法是Python和Ja ...
- TimSort in Java 8
在项目中使用了Collections.sort(list, comparator)对集合进行了排序,偶然间遇到异常IllegalArgumentException: "Comparison ...
- TimSort算法分析
Timsort是一种混合稳定的排序算法,采用归并排序混合插入排序的设计,在多种真实数据上表现良好. 它基于一个简单的事实,实际中大部分数据都是部分有序(升序或降序)的. 它于2002年由Tim Pet ...
- Java TimSort算法 源码 笔记
本来准备看Java容器源码的.但是看到一开始发现Arrays这个类我不是很熟,就顺便把Arrays这个类给看了.Arrays类没有什么架构与难点,但Arrays涉及到的两个排序算法似乎很有意思.那顺便 ...
- Timsort 算法
转载自:http://blog.csdn.net/yangzhongblog/article/details/8184707 Timsort是结合了合并排序(merge sort)和插入排序(inse ...
- JDK(二)JDK1.8源码分析【排序】timsort
如无特殊说明,文中的代码均是JDK 1.8版本. 在JDK集合框架中描述过,JDK存储一组Object的集合框架是Collection.而针对Collection框架的一组操作集合体是Collecti ...
- TimSort学习资料
深入理解 timsort 算法(1):自适应归并排序 如何找出Timsort算法和玉兔月球车中的Bug? Java TimSort算法 源码 笔记 Timsort https://en.wikiped ...
- TimSort Java源码个人解读
/*JDK 1.8 */ package java.util; /** * A stable, adaptive, iterative mergesort that requires far fewe ...
- Arrays.sort() ----- TimSort
Arrays.sort() Arrays.sort()对于基本类型使用的是DualPivotQuicksort双轴快速排序,而对于非基本类型使用的是TimSort,一种源自合并排序和插入排序的混合稳定 ...
随机推荐
- c++ ros 计算两点距离
#include <iostream> /* puts, printf */ #include <time.h> /* time_t, struct tm, time, loc ...
- 【2018.07.29】(深度优先搜索/回溯)学习DFS算法小记
参考网站:https://blog.csdn.net/ldx19980108/article/details/76324307 这个网站里有动态图给我们体现BFS和DFS的区别:https://www ...
- 【2018.07.27】(字符串/找相同)学习KMP算法小记
虽然说原理很好理解,但是代码理解了花费我一个下午的时间,脑阔痛 该注释的地方都标记了,希望以后看到这些代码我还能好好理解吧 学习的链接地址:https://www.cnblogs.com/teble/ ...
- 编程微语 2019-Summer
不支持重新生成不是好的代码生成器.重新生成就会覆盖手工修改,实用性大打折扣.相比工具,更接近玩具.2019-05-04 有很多个标准,各自为政,就相当于没有标准.目前地球的文档(如纯文本/Word/P ...
- Postgresql使用coalesce实现类似oracle的NVL方法
COALESCE (expression_1, expression_2, ...,expression_n)依次参考各参数表达式,遇到非null值即停止并返回该值. 如果所有的表达式都是空值,最终将 ...
- php的IP转换成整型函数ip2long()易出现负数
php中将IP转换成整型的函数ip2long()容易出现问题,在IP比较大的情况下,会变成负数.如下<?php$ip = "192.168.1.2";$ip_n = ip2l ...
- 在IntelliJ IDEA中启动tomcat出现Can't load AMD 64-bit .dll on a IA 32-bit' platform问题详解
第一查看jdk版本 第二查看IntelliJ IDEA中运行tomcat的配置的jdk 比较两个jdk版本是否一致.或者查看tomcat是64还是32位的
- php实现excel单元格合并,字体加粗居中等操作
使用的是phpexcel,基本用的原生语法,所见即所得,直接复制下面代码,即可: // 引用phpexcel类 $this->load->library('PHPExcel'); // 创 ...
- 激活函数,Batch Normalization和Dropout
神经网络中还有一些激活函数,池化函数,正则化和归一化函数等.需要详细看看,啃一啃吧.. 1. 激活函数 1.1 激活函数作用 在生物的神经传导中,神经元接受多个神经的输入电位,当电位超过一定值时,该神 ...
- LC 991. Broken Calculator
On a broken calculator that has a number showing on its display, we can perform two operations: Doub ...