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

11 Convex Hull

The document discusses algorithms for finding the convex hull of a set of points. It defines what a convex and concave polygon are, and explains that the convex hull is the smallest convex polygon containing all input points. It then describes Graham's scan algorithm, which finds the convex hull by starting with the lowest leftmost point, sorting others by polar angle around it, and adding points to the hull if they make a left turn. The algorithm runs in O(n log n) time due to the initial sorting step. Examples and pseudocode are provided to illustrate Graham's scan.

Uploaded by

the477577
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

11 Convex Hull

The document discusses algorithms for finding the convex hull of a set of points. It defines what a convex and concave polygon are, and explains that the convex hull is the smallest convex polygon containing all input points. It then describes Graham's scan algorithm, which finds the convex hull by starting with the lowest leftmost point, sorting others by polar angle around it, and adding points to the hull if they make a left turn. The algorithm runs in O(n log n) time due to the initial sorting step. Examples and pseudocode are provided to illustrate Graham's scan.

Uploaded by

the477577
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 24

Design and Analysis of Algorithms

Convex Hull

1
Convex vs. Concave

• A polygon P is convex if for every pair of


points x and y in P, the line xy is also in P;
otherwise, it is called concave.

P x y P x y

concave convex
2
The convex hull problem
concave polygon: convex polygon:

• The convex hull of a set of planar points is the


smallest convex polygon containing all of the points.

3
Graham’s Scan
• Graham scan is method of finding convex hull of a finite set of
points
• Steps:
• Start at point guaranteed to be on the hull. (the point with the
minimum y value i.e is leftmost and bottom most point in Y
co-ordinate)
• Sort remaining points by polar angles of vertices relative to
the first point.
• Go through sorted points, keeping vertices of points that have
left turns and dropping points that have right turns.

4
Graham’s Scan

5
Graham’s Scan

6
Graham’s Scan

7
Graham’s Scan

8
Graham’s Scan

9
Graham’s Scan

10
Graham’s Scan

11
Graham’s Scan

12
Graham’s Scan

13
Graham’s Scan

14
Graham’s Scan

15
Graham’s Scan

16
Graham’s Scan

17
Graham’s Scan

18
Graham’s Runtime
• Graham’s scan is O(n log n) due to initial
sort of angles.

19
A more detailed algorithm
Graham-Scan(Q)
1. Let p0 be the point in Q with the minimum y-coordinate, or the leftmost
such point in case of tie.
2. Let <p1, p2,…, pm> be the remaining points in Q, sorted by polar angle in
counterclockwise order around p0(if more than one point has the same angle,
remove all but the one that is farthest from p0).
3. Push(p0, S)
4. Push(p1, S)
5. Push(p2, S)
6. for i 3 to m:
7. do while the angle formed by points NEXT-TO-TOP(S), TOP(S), and
pi makes a nonleft turn.
8. do POP(S)
9. PUSH(pi, S)
10. Return S
20
21
22
Ex: Draw the convex hull for the following
points

23
Thank You

You might also like