简体   繁体   English

QuickHull算法的复杂性?

[英]Complexity of the QuickHull Algorithm?

I know the complexity is O(nlog(n)). 我知道复杂性是O(nlog(n))。 But why? 但为什么? How do you come to this answer? 你是如何得出这个答案的?

Any help would be much appreciated, I'm very interested to know! 任何帮助将不胜感激,我很有兴趣知道!

Its average case complexity is considered to be O(n log(n)) , whereas in the worst case it takes O(n^2) (quadratic). 它的平均情况复杂度被认为是O(n log(n)) ,而在最坏的情况下它需要O(n^2) (二次)。

Consider the following pseudo-code: 考虑以下伪代码:

QuickHull (S, l, r)

     if S={ }    then return ()
else if S={l, r} then return (l, r)  // a single convex hull edge
else
    z = index of a point that is furthest (max distance) from xy.
    Let A be the set containing points strictly right of (x, z)
    Let B be the set containing points strictly right of (z, y)
    return {QuickHull (A, x, z) U (z) U QuickHull (B, z, y)}

The partition is determined by the line passing through two distinct extreme points: the rightmost lowest r and the leftmost highest points l . 最右边的最低:分隔通过穿过两个不同的极端点的线确定r和最左边的最高分l Finding the extremes require O(n) time. 找到极端情况需要O(n)时间。

For the recursive function, it takes n steps to determine the extreme point z , but the cost of recursive calls depends on the sizes of set A and set B . 对于递归函数,确定极值点z需要n步,但递归调用的成本取决于集A和集B的大小。

Best case. 最好的情况。 Consider the best possible case, when each partition is almost balanced. 考虑最好的情况,每个分区几乎是平衡的。 Then we have 然后我们有

T(n) = 2 T(n/2) + O(n) . T(n) = 2 T(n/2) + O(n)

This is a familiar recurrence relation, whose solution is 这是一个熟悉的递归关系,其解决方案是

T(n) = O(n log(n)) . T(n) = O(n log(n))

This would occur with randomly distributed points. 随机分布的点会发生这种情况。

Worst case. 最差的情况。 The worst case occurs when each partition is an extremely unbalanced. 最坏的情况发生在每个分区非常不平衡时。 In that case the recurrence relation is 在这种情况下,递归关系是

T(n) = T(n-1) + O(n) 
     = T(n-1) + cn

Repeated expansion shows this is O(n^2) . 重复扩展显示这是O(n^2) Therefore, in the worst case the QuickHull is quadratic. 因此,在最坏的情况下,QuickHull是二次的。


http://www.personal.kent.edu/~rmuhamma/Compgeometry/MyCG/ConvexHull/quickHull.htm http://www.personal.kent.edu/~rmuhamma/Compgeometry/MyCG/ConvexHull/quickHull.htm

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

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