快速排序,需要更长时间 [英] Quick Sort,take longer

查看:91
本文介绍了快速排序,需要更长时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么方法quicksort需要更长的时间来排序向量是一个有序的向量而不是无序?

Why the method quicksort takes longer to sort a vector is a vector ordered than disordered?

推荐答案

Quicksort在大多数情况下更快,除非向量(在那个案例)已经排序了。



在更糟糕的情况下,它是O(n2),平均来说,它是O(n log n),这是我们通常的在描述算法时寻找,我们寻找最佳的平均复杂性速度,而不是更糟糕的情况。



如果我没记错,当数组排序时,简单的冒泡排序比QuickSort快。
Quicksort is faster in most cases, except when the vector (in that case) is already sorted.

In the worse case it is O(n2), on average, it is O(n log n) which is what we usually look for when describing algorithms, we look for the best average "complexity" speed, not the worse cases.

If I remember correctly, when an array is sorted, a simple bubble sort will be faster than QuickSort.


因为您使用了向量排序的方式,排序操作的数量多于随机排序向量的平均情况。我不明白为什么会出乎意料。



-SA
Because you used the vector ordered the way that the number of sorting operations is more than in an average case of randomly ordered vector. I don't see why it can come at surprise.

—SA


这篇关于快速排序,需要更长时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆