Java 和 .NET:为什么默认使用不同的排序算法?
只是想知道为什么 Java
和 .NET Framework
默认情况下使用不同的排序算法。
在Java中 Array.Sort()
使用合并排序 默认算法,如 Wikipedia.com 所说:
在 Java 中,Arrays.sort() 方法使用合并排序或调整排序 根据数据类型和实现效率进行快速排序 当数组元素少于七个时切换到插入排序 正在排序
Array.Sort/List.Sort()
使用 快速排序作为默认排序算法 (MSDN):
List.Sort() 使用 Array.Sort,后者使用 QuickSort 算法。这 实现执行不稳定的排序;也就是说,如果两个元素是 相等时,它们的顺序可能不会被保留。相比之下,稳定排序 保留相等元素的顺序。
通过查看伟大的“算法比较”表,我们可以看到两种算法都有从最坏情况和内存使用角度来看,行为有很大不同:
Java
和 .NET
都是用于企业解决方案开发的优秀框架,两者都有用于嵌入式开发的平台。那么为什么他们默认使用不同的排序算法,有什么想法吗?
编辑: 我看到有两个人已经投票决定结束这个问题,因为这个问题没有建设性。我相信 Java 和 .NET 是最流行的开发框架,因此找到任何关于此类决定的重要且有趣的想法(也许是事实)将非常有趣。
Just wondering why Java
and .NET Framework
uses different sorting algorithm by default.
In Java Array.Sort()
uses Merge Sort algorithm by default and as Wikipedia.com says:
In Java, the Arrays.sort() methods use merge sort or a tuned
quicksort depending on the datatypes and for implementation efficiency
switch to insertion sort when fewer than seven array elements are
being sorted
In .NET Framework Array.Sort/List.Sort()
uses Quick Sort as default sorting algorithm (MSDN):
List.Sort() uses Array.Sort, which uses the QuickSort algorithm. This
implementation performs an unstable sort; that is, if two elements are
equal, their order might not be preserved. In contrast, a stable sort
preserves the order of elements that are equal.
By looking at the great "Comparison of algorithms" table we can see that both algorithms has pretty different behaviour from Worst Case and Memory Usage perspectives:
Both Java
and .NET
are great Frameworks for Enterprise Solutions development, both has platforms for embedded development. So why they are using different sorting algorithm by default, any thoughts?
EDIT:
I see that two persons already voted to close this quesion as not constructive. I believe Java and .NET are most popular development Frameworks so it would be really interesting to find any non trivial and interesting thoughts, perhaps facts!, regarding such decision.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
两家不同公司的不同开发团队就其框架和组件的常见用例得出了不同的结论,并决定相应地实施。
Different development teams in two different companies came to different conclusions regarding the usual use case for their frameworks and components and have decided to implement accordingly.