简体   繁体   English

根据结果​​确定排序算法

[英]Determine sorting algorithm from results

I am now revising the sorting algorithms. 我现在正在修改排序算法。 Here is the question: 这是问题:

It is given that this sorting algorithm is written in C, and treats 'a' and 'A' as equal, and after running this sorting algorithm, the results are as follows: 假定此排序算法是用C编写的,并且将'a'和'A'视为相等,并且运行此排序算法后,结果如下:

10000 random data -> 0.016 sec 10000个随机数据-> 0.016秒
100000 random data -> 0.304 sec 100000随机数据-> 0.304秒

10000 ordered data -> 0.006 sec 10000个有序数据-> 0.006秒
100000 ordered data -> 0.108 sec 100000个有序数据-> 0.108秒

10000 reversed data -> 0.010 sec 10000个反向数据-> 0.010秒
100000 reversed data -> 0.138 sec 100000个反向数据-> 0.138秒

Question: In point form briefly state the conclusions that you can draw from the test results above. 问题:以点的形式简要说明您可以从上述测试结果中得出的结论。

What I have done 我做了什么
I know this sorting algorithm is non-stable (as stated in the question), and I can guess it is a quick sort. 我知道这种排序算法是不稳定的 (如问题中所述),我可以猜测它是一种快速排序。 I know that quick sort has worst case O(n^2) , average and best case O(n log n) , but I have got no idea how to explain from the results, I can't just say oh its because its non-stable and quick sort have bad results in reversed order, so i can determine it's quick sort. 我知道快速排序具有最坏情况O(n ^ 2) ,平均情况和最佳情况O(n log n) ,但是我不知道如何从结果中进行解释,我不能只说哦,因为它不-稳定和快速排序的顺序相反,结果不好,因此我可以确定它是快速排序的。

Are there anything specific I can tell from the result? 我可以从结果中看出什么具体信息吗? It would be nice if there are maths calculations or some other important observations from the results. 如果结果中包含数学计算或其他重要观察结果,那将是很好的。

We can tell that this isn't a quadratic-time algorithm like selection sort or insertion sort, since raising the input size by a factor of 10 raised the runtime by a factor of 13-19. 我们可以说这不是像选择排序或插入排序这样的二次时间算法,因为将输入大小增加10倍将运行时间增加13-19倍。 This is behavior we'd expect from an O(n*log(n)) average-case algorithm, like mergesort or a good quicksort. 这是我们期望的O(n*log(n))平均情况算法的行为,例如mergesort或良好的quicksort。

We can tell that the algorithm isn't adaptive, or at least, not very adaptive. 我们可以说该算法不是自适应的,或者至少不是很自适应的。 An adaptive algorithm would have performed much better on the sorted input, and probably on the reversed input, too. 自适应算法在分类的输入上可能执行得更好,并且在反向输入上也可能执行得更好。 In particular, raising the size of the sorted input by a factor of 10 would have raised the runtime by a factor of about 10. While the algorithm did do better on sorted or reverse-sorted input than random input, this looks more like a result of, say, more effective branch prediction in those cases. 特别是,将排序的输入的大小增加10倍将使运行时间增加大约10倍。虽然该算法在排序或反向排序的输入上比随机输入做得更好,但看起来更像是结果在这些情况下更有效的分支预测。

We don't have any information that would indicate whether the sort is stable. 我们没有任何信息可以表明排序是否稳定。

I don't see anything that would distinguish whether this is a quicksort, mergesort, heapsort, or other O(n*log(n)) algorithm. 我看不出有什么可以区分这是快速排序,合并排序,堆排序还是其他O(n*log(n))算法。 We can exclude certain types of pivot selection for quicksort - for example, a quicksort that always picks the first element as the pivot would run in quadratic time on sorted input - but beyond that, I can't tell. 我们可以排除某些类型的枢轴选择来进行快速排序-例如,由于枢轴将在排序后的输入上以二次时间运行,因此快速排序始终选择第一个元素,但我无法分辨。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM