VOOZH about

URL: https://www.geeksforgeeks.org/dsa/quickhull-algorithm-convex-hull/

โ‡ฑ Quickhull Algorithm for Convex Hull - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Quickhull Algorithm for Convex Hull

Last Updated : 23 Jul, 2025

Given a set of points, a Convex hull is the smallest convex polygon containing all the given points.

๐Ÿ‘ Convex-Hull

Input : points[] = {{0, 3}, {1, 1}, {2, 2}, {4, 4},
{0, 0}, {1, 2}, {3, 1}, {3, 3}};
Output : The points in convex hull are:
(0, 0) (0, 3) (3, 1) (4, 4)
Input : points[] = {{0, 3}, {1, 1}
Output : Not Possible
There must be at least three points to form a hull.
Input : points[] = {(0, 0), (0, 4), (-4, 0), (5, 0),
(0, -6), (1, 0)};
Output : (-4, 0), (5, 0), (0, -6), (0, 4)

Recommended Practice

We have discussed following algorithms for Convex Hull problem. Convex Hull | Set 1 (Jarvisโ€™s Algorithm or Wrapping)Convex Hull | Set 2 (Graham Scan) The QuickHull algorithm is a Divide and Conquer algorithm similar to QuickSort. Let a[0...n-1] be the input array of points. Following are the steps for finding the convex hull of these points.

  1. Find the point with minimum x-coordinate lets say, min_x and similarly the point with maximum x-coordinate, max_x.
  2. Make a line joining these two points, say L. This line will divide the whole set into two parts. Take both the parts one by one and proceed further.
  3. For a part, find the point P with maximum distance from the line L. P forms a triangle with the points min_x, max_x. It is clear that the points residing inside this triangle can never be the part of convex hull.
  4. The above step divides the problem into two sub-problems (solved recursively). Now the line joining the points P and min_x and the line joining the points P and max_x are new lines and the points residing outside the triangle is the set of points. Repeat point no. 3 till there no point left with the line. Add the end points of this point to the convex hull.

Below is C++ implementation of above idea. The implementation uses set to store points so that points can be printed in sorted order. A point is represented as a pair


Output
The points in Convex Hull are:
(0, 0) (0, 3) (3, 1) (4, 4) 

Time Complexity: The analysis is similar to Quick Sort. On average, we get time complexity as O(n Log n), but in worst case, it can become O(n2)

space complexity : O(n) 

If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Comment