Divide and Conquer For Convex Hull
Ngonidzashe Zanamwe
Abstract— The divide and concqur approach has many applications in computer science. With this approach a large problem is broken down into small and manageable subproblems and each is solved then the solutions are combined to give the grand solution to the problem. The problem of finding the convex hull of a polygon can be viewed as one problem that can be solved using the divide and conqurer approach. This paper therefore presents a discussion on the divide and conquer for the Convex Hull. The paper looks at generic divide and conquer approach before using the approach in finding the convex hull of a polygon. The paper presents a step by step procedure for finding the convex hull using the divide and conqurer approach. Also, the paper discusses running times of the Convex Hull divide-and-conquer algorithm, advantages and disadvantages of the divide and conquers approach for convex hull. The paper concludes by giving other algorithms for solving the convex hull problem apart from the divide and conquer.
Index Terms—divide and conqurer, convex hull, polygon, divide and conqurer for convex hull. —————————— ——————————
1 I
NTRODUCTIONHIS paper presents a discussion on the divide and conquer for Convex Hull (hereinafter referred to as CH). The paper begins by looking at the divide and conquer in general before focusing on its applications in computational geometry, notably to the CH problem. This paper looks at two distinct ways of computing the convex hull using the divide and conquer approach. Also, the paper discusses running times of Convex Hull divide-and-conquer algorithm, advantages and disadvantages of the divide and conquers approach for convex hull. The paper concludes by giving other algorithms for solving the convex hull problem apart from the divide and con-quer approach.
1.1 Divide and Conquer algorithms
Naher and Schmitt [1] note that divide and conquer algo-rithms solve problems by dividing them into instances, solving each instance recursively and merging the corre-sponding results to a complete solution. Further, [1] as-serts that all instances have exactly the same structure as the original problem and can be solved independently from each other, and so can easily be distributed over a number of parallel processes or threads. The divide and conquer approach is presented in Fig. 1 below.
Figure 1: The divide and conquer approach
The above diagram shows that if one is faced with a prob-lem of size n, one begins by dividing it into two sub-problems of size n/2 each and then finds a solution to each problem then merges the solutions to sub-problems. Similar assertions were made by [5], he presents the following divide and conquer algorithm: if trivial (small), solve it “brute force”
else
{ divide into a number of sub-problems;
solve each sub-problem recursively;
combine solutions to sub-problems; }
1.2 Polygon
A polygon is defined as a closed shape with more than two sides or line segments. A simple polygon has no two consecutive edges that are intersecting.
————————————————
Ngonidzashe Zanamwe is with the University of Zimbabwe, Zimbabwe
1.3 Convexity
A convex is a polygon in which any line joining two points within the polygon lies within the polygon. Alex-ander Kolesnikov [7] gives similar definitions of convexi-ty, the first is that, a subset set S of the plane is called convex if and only if for any pair of points P, QS the line segment PQ is completely contained in S. The second goes as, a set S is convex if it is exactly equal to the inter-section of all the half planes containing it. The figures below show convex and non-convex shapes.
Figure 2: The convex and non-convex shapes
1.3. Convex Hull
Mohammed Nadeem Ahmed and Raghavendra Kyatha [2] establish that the Convex Hull of a set Q of points is the smallest convex polygon P, for which each point in Q is either on the boundary of P or in its interior. In line with the above, [4] asserts that the convex hull of a set S of points, denoted hull(S) is the smallest polygon P for which each point of S is either on the boundary or in the interior of P. Similarly, [7] establishes that the convex hull CH(P) of a finite point set P is the smallest convex poly-gon that contains P. Figure 3 below shows a convex hull P.
Figure 3: Convex Hull P
1.4 Intuition:
If each point is represented by a nail sticking out from a board and you take a rubber band and lower it over the nails, so as to completely encompass the set of nails, and then let the rubber band naturally contract, the rubber band will give you the edges of the convex hull of the set of points, and those nails that correspond to a change in slope of the rubber band represent the extreme points of the convex hull [4].
1.5 Convex Hull Problem
From the above definition it can thus be said that a con-vex hull problem is one where given a set of points or coordinates one is asked to come up with the smallest polygon in which all points are either inside or on the edge of the polygon.
1.6 Finding the convex hull using divide and conquer
Souvaine [3]establishes that in order to find the convex hull using a divide-and-conquer approach, one has to follow these steps:
sort points (p1, p2, . . . , pn) by their x-coordinate
recursively find the convex hull of p1 through pn/2 recursively find the convex hull of pn/2 +1 through pn
merge the two convex hulls
A more detailed algorithm for finding a Convex Hull is presented in [6]. The algorithm is as follows:
Hull(S) :
If |S| <= 3, then compute the convex hull by brute force in O(1) time and return.
Otherwise, partition the point set S into two sets A and B, where A consists of half the points with the lowest x co-ordinates and B consists of half of the points with the highest x coordinates.
Recursively compute HA = Hull(A) and HB = Hull(B). Merge the two hulls into a common convex hull, H, by computing the upper and lower tangents for HA and HB and discarding all the points lying between these two tangents.
2. A
PPROACHES TO FINDING THE CONVEX HULL There are two approaches to computing the convex hull and the approaches are here named approach A and ap-proach B. The next section explores these apap-proaches in greater detail beginning with approach A.2.1 Approach A
This approach involves a number of steps which include, sorting the points, dividing the set of points into two sets, recursive computation of convex hulls for each subset of points and merging the convex hulls. Below is a detailed explanation of each of the above steps.
2.1.1 Sorting the points or coordinates
This involves sorting the points in increasing order of their x-coordinates with ties resolved by increasing order of y coordinates. For example if one is given the following set of points S: (2,12), (4,17), (10,19), (12,15), (15,19), (7,20), (18,20), (16,10), (18,2), (14,7), (20,11), (8,9), (4,6) and (9,1). If these points are sorted according to be explanation given above, we end up with the following arrangement, P1(2,12), P2(4,6), P3(4,17), P4(7,20), P4(8,9), P6(9,1), P7(10,19), P8(12,15), P9(14,7), P10(15,19), P11(16,10), P12(18,2) , P13(18,20), and P14(20,11). The points are shown in the figure 4 below:
Figure 4: The Points
2.1.2 Dividing points
This step involves partitioning the point set S into two sets A and B, where A consists of half the points with the lowest x coordinates and B consists of half of the points with the highest x coordinates. For instance, in our exam-ple set A will consist points P1 through P7 whereas set B will consist points P8 to P14. This partition is illustrated in figure 5 below.
Figure 5: The Partition
Each subset in the above figure has 7 elements. We now subdivide each subset into two subsets one with four el-ements and the other with three elel-ements. The algorithm above stipulates that once the number of points in each partition is 3 or less you construct the convex hull, other-wise continue dividing. The final partitions are in figure 6 below.
Figure 6: Final Partitions
2.1.3 Computation of convex hulls
This involves constructing convex hulls by joining all points in each subset in the diagram above. For instance, join P2, P3 and P4 to form triangle P2P3P4, then join P5, P6 and P7 to form triangle P5P6P7, join P8P9, join P10P11 and lastly join P12, P13 and P14 to form triangle P12P13P14. This goes on until the points in the last parti-tion are joined as shown in the shown in the diagram be-low. The computed convex hulls are shown in figure 7 below.
Figure 7: Computed Convex Hull
The convex hulls in the figure above must be combined by removing the partitions in the reverse order in which they were placed; this implies that, remove lines L4 and
L5 first. If we remove L4, we then join P1 to hull P2P3P4. If we remove L5, we then join the two lines as illustrated in Figure 8 below.
Figure 8: Two Lines Joined
The next stage is to remove lines L2 and L3, if we remove L2, then we join P4 to P7 and P2 to P6. If we remove L2, then we join P10 to P13 and P9 to P12. After that, we re-move all non-convex edges such as P5P6, P2P3, P10P11 and so on. This leaves one with two convex hulls HA and HB as shown in figure 9 below.
Figure 9: Convex Hulls HA and HB 2.1.4 Merging convex hulls
This step involves merging the two convex hulls into a single convex hull. Also, this involves computing the lower and upper tangents.
2.1.4.1 Computing the lower tangent
One thing that simplifies the process of computing the tangents is that the two point sets HA and HB are sepa-rated from each other by a vertical line (assuming no du-plicate x coordinates). The algorithm for computing the lower tangent operates by a simple ``walking'' procedure. We initialize x to be the rightmost point of convex hull HA and y is the leftmost point of convex hull HB. (These can be found in linear time.)Lower tangency is a condition that can be tested locally by an orientation test of the two vertices and neighbour-ing vertices on the hull. We iterate the followneighbour-ing two loops, which march x and y down, until they reach the points lower tangency. In our example the rightmost point of HA is P6 and the leftmost point of HB is P8. The actual algorithm for computing the tangent is given be-low:
LowerTangent(HA , HB )
{ x = the rightmost point of HA; y = the leftmost point of HB;
While (xy != a lower tangent for HA and HB) do { While (xy != a lower tangent to HA) do
x = x – 1; // move x clockwise While (xy != a lower tangent to HB) do
y = y + 1; //move y counter-clockwise }
return xy; }
In implementing the above algorithm, start with tangent P6P8. This is not a lower tangent for both HA and HB. Move y counter-clockwise and the tangent constructed is P6P9. This is a lower tangent for HA but not even a tan-gent for HB. Move y counter-clockwise and the tantan-gent constructed is P6P12. This is shown in figure 10 below.
Figure 10: Computing the Lower Tangent
The tangent is P6P12 is both a lower tangent for HA and HB, so eliminate the other two tangents to remain with the figure 11 below.
Figure 11: Computing the Lower Tangent
2.1.4.2 Computing the upper tangent
The algorithm for computing the upper tangent again operates by a simple ``walking'' procedure. We initialize x to be the rightmost point of convex hull HA and y is the leftmost point of convex hull HB. Upper tangency is a condition that can be tested locally by an orientation test of the two vertices and neighbouring vertices on the hull. We iterate the following two loops, which march x and y up, until they reach the points upper tangency. In our example the rightmost point of HA is P6 and the leftmost point of HB is P8. This is shown in figure 12 below. The actual algorithm for computing the tangent is given be-low:UpperTangent(HA , HB )
{ x = the rightmost point of HA; // P6 y = the leftmost point of HB; // P8
While (xy != a upper tangent for HA and HB) do { While (xy != a upper tangent to HA) do
x = x - 1; // move x counter-clockwise While (xy != a upper tangent to HB) do
y = y + 1; //move y clockwise} return xy; }
Figure 12: Computing the Upper Tangent
After implementing the algorithm for computing the up-per tangent, it was established that the upup-per tangent for both HA and HB is P4P13 as shown above. If one discards the other tangents you are left with figure 13 below.
Figure 13: After Discarding other Tangents
We now have the upper and lower tangents so we can now merge our two convex hulls and eliminate non-convex hull edges. The final non-convex hull is shown in fig-ure 14 below.
Figure 14: Final Convex Hull
The asymptotic running time of the algorithm for compu-ting the lower tangent can be expressed by a recurrence. Given an input of size n, consider the time needed to per-form all the parts of the procedure, ignoring the recursive calls. This includes the time to partition the point set, compute the two tangents, and return the final result. Clearly the first and third of these steps can be performed
in O(n) time, assuming a linked list representation of the hull vertices.
2.2. Approach B - QuickHull
The second approach is commonly known as the QuickHull. The main idea is that, we are given a set of points P, and line segment lr is a chord of the convex hull CH(P): a chord goes from the leftmost highest to the rightmost lowest point in the set.
1. Among the given points, find the one which is farthest from lr.
Call the point z.
2. The points inside the triangle lrc cannot be on the hull. Put them in a set S0.
3. Put the points which lie outside edge lz in set A, and points outside edge rz in set B.
Once the partition is done, we recursively invoke QuickHull procedure on sets S1 and S2.
The algorithm is as follows: findHull (S, l, r)
if S={ } then return ()
else if S={l, r} then return (l, r) //single convex hull edge else
z = index of a point that is furthest (max dist.) from xy. A = set containing points strictly right of (x, z); B = set containing points strictly right of (z, y); return {findHull (A, x, z) U (z) U findHull (B, z, y)}
2.2.1 Implementation of the Algorithm
Use shall be made of the above example where we are given the following set of 14 points sorted in increasing order of their x-coordinates with ties resolved by increas-ing order of y coordinates. S = {P1(2,12), P2(4,6), P3(4,17), P4(7,20), P4(8,9), P6(9,1), P7(10,19), P8(12,15), P9(14,7), P10(15,19), P11(16,10), P12(18,2) , P13(18,20), P14(20,11)}. The algorithm above computes the upper hull. The lower hull can be computed in a similar fashion. In this paper we compute both the lower and the upper hulls simulta-neously as we shall see in the sections below.
Step 1: findHull(S, r, l).
Here S is the set of the above points, r is the rightmost lowest point and l is leftmost highest point and these points are P1 and P14 as shown in the figure 15 below.
Figure 15: the rightmost lowest point and leftmost highest point
Step 2: if S = {} return ().
In this case S is not null, so we proceed to the next step.
Step 3: if S ={l,r} return (r,l)
In this instance set S has more than two elements so we proceed to the next step
Step4: z, y = indices of points that are furthest (max dist.) from lr.
This step involves finding two extreme points one on the right and another on the left of line P1P14. The furthest points are P6 and P4. These points are our labelled z and y as shown in the diagram below.
2.2.2 Selecting the furthest points
How should the furthest points z and y be selected? There are a number of possible selection criteria that one might think of. The method that is most often proposed is to let
z and y be the points that maximize the perpendicular distance from the line lr. (For example, another possible choice might be the point that maximizes the angle zlr or
zrl OR ylr or yrl. It turns out that these can be are very poor choices because they tend to produce imbalanced partitions of the remaining points.).
Step5: Construct triangles P1P6P14 and P1P4P14 and dis-card all points inside these two triangles as shown in the figure 16 below.
Figure 16: Constructing Triangles
Step 6: A = set containing points strictly right of (l, z) (l,z) is equated in the diagram above to the line or chord P1P4 and the points that lie to the right of this line are contained in set A, where A= {P3}
Step 7: B = set containing points strictly right of (z, r). (z,r) is equivalent to line P4P14 and the points that lie to the right of this line are contained in set B where B ={P7, P10, P13}
Step 8: C = set containing points strictly right of (y, r). (y,r) is equivalent to line P6P14 and the points that lie to the right of this line are contained in set C where C ={P12}
Step 9: D = set containing points strictly right of (z, r).
(z,r) is equivalent to line P1P6 and the points that lie to the right of this line are contained in set D where D ={P2}
Step 10: Now we need to find the hull of each of the above sets A through D. The hulls of A,
C and D are easy to compute because each of the sets has a single element. The hull of each set computed by just joining the point in each set to the respective edges for instance hull of A is the triangle P1P3P4, hull for C is tri-angle P1P2P6 and hull for D is P6P12P14. As for hull of B we have to repeat step 4 and step 5 above. As for B we need to find the furthest point from line (z,r) or P4P14. The furthest point is P13 so we construct hull P4P13P14 and there is no any point on the right of any edge now. Figure 17 below is a result of implementation of step 6 to step 10.
Figure 17:Implementation of step 6 to step 10.
Step 11: return, union of all convex hulls in the figure above.
This involves elimination of non-convex edges such as P1P14, P4P14 and so on to remain with the final convex hull as shown in figure 18 below.
Figure 18: Final Convex Hull
The QuickHull algorithm runs in O(n log n) time for fa-vourable inputs but can take as long as O(n2) time for un-favourable inputs. The QuickHull tends to perform very well in practice. The intuition is that in many applications most of the points lie in the interior of the hull. For exam-ple, if the points are uniformly distributed in a unit square, then it can be shown that the expected number of points on the convex hull is O(log n).
3. E
FFICIENCY OFQ
UICKH
ULL ALGORITHM Worst case: Θ( n2)Average case: Θ( n log n)
If points are not initially sorted by x-coordinate value, this can be accomplished in Θ( n log n)
3.1 Analysis of divide and conquer
Initial sorting takes O(N log N) time Recurrence T(N) = 2T(N/2) + O(N) O(N) for merging (computing tangents) Recurrence solves to T(N) = O(N log N)
4. C
ONVEXH
ULLA
PPLICATIONSConvex hulls have many applications in robotics, shape analysis and line fitting.
5. R
UNNINGT
IMES OFC
ONVEXH
ULLD
IVIDE-
AND-C
ONQUERA
LGORITHM5.1 Sequential Algorithm:
Sorting requires O(nlog n) time.
However, it is critical to note that the sort only needs to be performed once at the beginning of the algorithm as a
pre-processing step and not every time through the recur-sion.
The stitch step requires Θ(log n) time to determine the lines of support (i.e., the common tangent lines) and Θ(n) time to reorder (compress) the data.
So, there is Θ(nlog n) pre-processing time and T(n) = 2T(n / 2) + O(n) = O(nlog n) running time.
Therefore, the running time for the algorithm is optimal at Θ(nlog n).
5.2 Mesh Algorithm:
Given n points, arbitrarily distributed one point per pro-cessor on a mesh of size n, the convex hull of the set S of points can be determined in Θ( ) time. First, sort the points into shuffled row major order so that the following holds (geometric points on left side of figure mapped to mesh quadrants as shown in right side of figure 19):
Figure 19: Mesh Algorithm
5.3 Binary Search
Binary search from S1 to S2 and from S2 to S1, where after each iteration, the remaining data is compressed together so that the running time of the binary search is linear in the edge length of the sub-mesh that the points initially reside in.
Broadcast the 4 tangent points.
Eliminate points inside of quadrilateral and renumber. Running time of binary search is B(n) = B(n / 2) +Θ( ) = Θ( ).
So, the running time of the divide-and-conquer convex hull algorithm on a mesh of size n is T(n) = T(n / 4) + B(n) = T(n / 4) +Θ(n1/2 ) = Θ( ),
plus Θ( ) for the initial sort, which is Θ( ).
6. A
DVANTAGES OF THED
IVIDE ANDC
ONQUER APPROACH FOR FINDING THE CONVEX HULL6.1 Algorithm efficiency
The QuickHull recursively subdivides point set S, and assembles the convex hull H(S) by “merging” the sub-problem results or partial solutions. The base case re-quires O(1), constant-bounded time. Thus the divide and conquer algorithm will have O(n log n) complexity.
6.2 Subdivision allows Parallelism
Divide-and-conquer algorithms are adapted for execution in multi-processor machines, especially shared memory systems as in the testing of robots using convex hulls; where the communication of data between processors does not need to be planned in advance. Thus distinct sub-problems can be executed on different processors.
Ideal for solving difficult and complex problems
Divide and conquer is a powerful tool for solving concep-tually difficult problems, such as the classic Tower of Ha-noi puzzle: all it requires is a way of breaking the prob-lem into sub-probprob-lems, of solving the trivial cases and of combining sub-problems to the original problem.
Memory access
Divide-and-conquer algorithms naturally tend to make efficient use of memory caches. The reason is that once a sub-problem is small enough, it and all its sub-problems can, in principle, be solved within the cache, without ac-cessing the slower main memory. An algorithm designed to exploit the cache in this way is called cache oblivious, because it does not contain the cache size(s) as an explicit parameter.
7. D
ISADVANTAGES OF THED
IVIDE ANDC
ONQUER APPROACHRecursion which is the basis of divide and conquer is slow, the overhead of the repeated subroutine calls, along with that of storing the call stack.
Inability to control or guarantee sub-problem size results in sub-optimum worst case time performance.
Requires a lot of memory for storing intermediate results of sub-convex hulls to be combined to form the complete convex hull.
The use of divide and conquer is not ideal if the points to be considered are too close to each other such that other approaches to convex hull will be ideal.
Is complicated if a large base cases are to be implemented for performance reasons
8. A
LGORITHMS FORC
ONVEXH
ULL PROBLEM Table 1 shows algorithms for the convex hull problem.Table 1: Algorithms for Convex Hull problem
Algorithm Speed Discovered by Brute Force O(n3) [Anon, the dark
ages]
Gift Wrapping O(nh) [Chand & Kapur, 1970] Graham Scan O(n log n) [Graham, 1972] Jarvis’ March O(nh) [Jarvis, 1973] QuickHull O(nh) [Eddy, 1977], [Bykat, 1978] Divide-and-Conquer
O(n log n) [Preparata & Hong, 1977] Monotone Chain
O(n log n) [Andrew, 1979] Incremental
O(n log n) [Kallay, 1984] Marriage-before-
Conquest
O(n log h) [Kirkpatrick & Seidel, 1986]
R
EFERENCES[1] Naher S. and Schmitt D. (2008) A Framework for Multi-Core Imple-mentations of Divide and Conquer Algorithms and its Application to the Convex Hull Problem, CCCG, Montreal, Quebec, August 13–15 [2] Mohammed Nadeem Ahmed and Raghavendra Kyatham (n.d.)
Com-putational Geometry - Part II.
[3] Souvaine D. (2005) Dynamic Convex Hull and Order Decomposable Problems, Tufts University.
[4] Miller, R. (1996) Computational Geometry (Divide and Conquer) [5] Simonas Šaltenis (2004), Advanced Algorithm
Design and Analysis
[6] David M. Mount (2000), Computational Geometry. University of Maryland, College Park. Available at: http://www.cs.wustl.edu/~pless/506/l3.html
[7] Alexander Kolesnikov (n.d.) Design of Spatial Information Systems: Convex Hull, University of Joensuu, Joensuu, Finland
Ngonidzashe Zanamwe holds BSc and MSc degrees in Computer Science from the University of Zimbabwe. He is currently doing his PhD in Computer Scince with the University of Zimbabwe. He is currently employeed as a lecturer in Computer Science with the University of Zimbabwe. He has published five papers in internation-al journinternation-als and has presented papers at internationinternation-al conference. His research interests are in algorithms, e-learning and e-commerce.