0% found this document useful (0 votes)
152 views

Convex Hull Algorithms - Divide and Conquer - Algorithm

This document describes a divide and conquer algorithm for computing the convex hull of a set of points in O(n log n) time. It divides the points into left and right halves, recursively computes the convex hulls of each half, and then merges the two hulls into the final convex hull. The key steps are: 1) Divide by sorting points by x-coordinate and splitting at the median, 2) Conquer by recursively computing hulls on each half, and 3) Merge the two hulls efficiently in O(n) time using an algorithm described in another reference. The overall complexity is O(n log n) due to the initial sorting and divide/conquer parts.

Uploaded by

Nandan Banerji
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
152 views

Convex Hull Algorithms - Divide and Conquer - Algorithm

This document describes a divide and conquer algorithm for computing the convex hull of a set of points in O(n log n) time. It divides the points into left and right halves, recursively computes the convex hulls of each half, and then merges the two hulls into the final convex hull. The key steps are: 1) Divide by sorting points by x-coordinate and splitting at the median, 2) Conquer by recursively computing hulls on each half, and 3) Merge the two hulls efficiently in O(n) time using an algorithm described in another reference. The overall complexity is O(n log n) due to the initial sorting and divide/conquer parts.

Uploaded by

Nandan Banerji
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Convex Hull Algorithms: Divide and Conquer

Before reading this article, I recommend you to visit following two articles. Many concepts and codes are referred from
there.

1. Divide and Conquer Algorithm (https://en.wikipedia.org/wiki/Divide_and_conquer_algorithm)


2. Convex Hull Algorithms: Jarvis’s March (https://algorithmtutor.com/Convex-Hull-Algorithms-Jarvis-s-March/)
(Introduction Part)
3. An efficient way of merging two convex hulls (https://algorithmtutor.com/An-efficient-way-of-merging-two-
convex-hull/)

Introduction
In this article, I talk about computing convex hull using the divide and conquer technique. The divide and conquer
algorithm takes O(n log n) time. As in the usual divide and conquer algorithms, it has three major steps:

1. Divide: We divide the set of n points into two parts by a vertical line into the left and right halves.
2. Conquer: We recursively find the convex hull on left and right halves.
3. Combine or Merge: We combine the left and right convex hull into one convex hull.

Divide and Conquer steps are straightforward. The merge step is a little bit tricky and I have created separate post
(https://algorithmtutor.com/An-efficient-way-of-merging-two-convex-hull/) to explain it.

Algorithm
1. Before calling the method to compute the convex hull, once and for all, we sort the points by x-coordinate. This
step takes O(n log n) time.
2. Divide Step: Find the point with median x-coordinate. Since the input points are already sorted by x-coordinate,
this step should take constant time. Depending upon your implementation, sometime it may take up to O(n) time.
3. Conquer Step: Call the procedure recursively on both the halves.
4. Merge Step: Merge the two convex hulls computed by two recursive calls in the conquer step. The merge
procedure should take O(n) time.

Again, I have described the merging procedure on a separate post (https://algorithmtutor.com/An-efficient-way-of-


merging-two-convex-hull/). The merge procedure given in the implementation is used from that post.

Implementation
The python implementation of the main procedure is given below.

1 def convex_hull(points):
2 if len(points) == 1:
3 return points
4
5 left_half = convex_hull(points[0: len(points)/2])
6 right_half = convex_hull(points[len(points)/2:])
7 return merge(left_half, right_half)

Remember the input points must be pre-sorted by x-coordinates before calling this function.

1 points = sorted(points, key = lambda p: p.x)


The program returns when there is only one point left to compute convex hull. The convex hull of a single point is
always the same point. Note: You can return from the function when the size of the points is less than 4. In that case you
can use brute force method in constant time to find the convex hull.

Complexity
The divide step and conquer steps require O(n log n) time. So the recurrence relation for the divide and conquer part
is:
n
T (n) = 2T ( ) + O(n)
2

.
Which gives the complexity of O(n log n). The initial pre-sort requires extra O(n log n) time. The overall complexity
is, therefore, O(n log n).

References
1. Mount, D. M. (n.d.). CMSC 754 Computational Geometry. Lecture. Retrieved August 23, 2018, from
https://www.cs.umd.edu/class/spring2012/cmsc754/Lects/cmsc754-lects.pdf
(https://www.cs.umd.edu/class/spring2012/cmsc754/Lects/cmsc754-lects.pdf)
2. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (n.d.). Introduction to algorithms (3rd ed.). The MIT Press.

 Convex Hull (/tags/Convex-Hull/)

You might also like