Download - Algorithms - cs.princeton.edu
![Page 1: Algorithms - cs.princeton.edu](https://reader031.vdocuments.site/reader031/viewer/2022012016/615a9172315fff046f3c09bd/html5/thumbnails/1.jpg)
Algorithms, 4th Edition · Robert Sedgewick and Kevin Wayne · Copyright © 2002–2011 · September 24, 2011 8:59:25 AM
AlgorithmsF O U R T H E D I T I O N
R O B E R T S E D G E W I C K K E V I N W A Y N E
GRAHAM SCAN DEMO
![Page 2: Algorithms - cs.princeton.edu](https://reader031.vdocuments.site/reader031/viewer/2022012016/615a9172315fff046f3c09bd/html5/thumbnails/2.jpg)
• Choose point p with smallest y-coordinate.
• Sort points by polar angle with p.
• Consider points in order, and discard unless that would create a ccw turn.
2
Graham scan
p
![Page 3: Algorithms - cs.princeton.edu](https://reader031.vdocuments.site/reader031/viewer/2022012016/615a9172315fff046f3c09bd/html5/thumbnails/3.jpg)
• Choose point p with smallest y-coordinate.
• Sort points by polar angle with p.
• Consider points in order, and discard unless that would create a ccw turn.
3
Graham scan
1
0
4
5
67
8
10
1112
2
3
9
![Page 4: Algorithms - cs.princeton.edu](https://reader031.vdocuments.site/reader031/viewer/2022012016/615a9172315fff046f3c09bd/html5/thumbnails/4.jpg)
• Choose point p with smallest y-coordinate.
• Sort points by polar angle with p.
• Consider points in order, and discard unless that would create a ccw turn.
1
0
3
4
5
67
8
10
1112
2
4
Graham scan
9
![Page 5: Algorithms - cs.princeton.edu](https://reader031.vdocuments.site/reader031/viewer/2022012016/615a9172315fff046f3c09bd/html5/thumbnails/5.jpg)
• Choose point p with smallest y-coordinate.
• Sort points by polar angle with p.
• Consider points in order, and discard unless that would create a ccw turn.
1
0
4
5
67
8
10
1112
2
5
Graham scan
3
9
![Page 6: Algorithms - cs.princeton.edu](https://reader031.vdocuments.site/reader031/viewer/2022012016/615a9172315fff046f3c09bd/html5/thumbnails/6.jpg)
• Choose point p with smallest y-coordinate.
• Sort points by polar angle with p.
• Consider points in order, and discard unless that would create a ccw turn.
1
0
4
5
67
8
10
1112
2
6
Graham scan
3
9
![Page 7: Algorithms - cs.princeton.edu](https://reader031.vdocuments.site/reader031/viewer/2022012016/615a9172315fff046f3c09bd/html5/thumbnails/7.jpg)
• Choose point p with smallest y-coordinate.
• Sort points by polar angle with p.
• Consider points in order, and discard unless that would create a ccw turn.
7
Graham scan
1
0
3
4
5
2
67
8
10
1112
9
![Page 8: Algorithms - cs.princeton.edu](https://reader031.vdocuments.site/reader031/viewer/2022012016/615a9172315fff046f3c09bd/html5/thumbnails/8.jpg)
• Choose point p with smallest y-coordinate.
• Sort points by polar angle with p.
• Consider points in order, and discard unless that would create a ccw turn.
5
8
Graham scan
67
8
10
1112
9
1
0
4 2
3
![Page 9: Algorithms - cs.princeton.edu](https://reader031.vdocuments.site/reader031/viewer/2022012016/615a9172315fff046f3c09bd/html5/thumbnails/9.jpg)
• Choose point p with smallest y-coordinate.
• Sort points by polar angle with p.
• Consider points in order, and discard unless that would create a ccw turn.
1
0
4
5
9
Graham scan
2
67
8
10
1112
9
3
![Page 10: Algorithms - cs.princeton.edu](https://reader031.vdocuments.site/reader031/viewer/2022012016/615a9172315fff046f3c09bd/html5/thumbnails/10.jpg)
• Choose point p with smallest y-coordinate.
• Sort points by polar angle with p.
• Consider points in order, and discard unless that would create a ccw turn.
1
0
4
5
2
10
Graham scan
67
8
10
1112
9
3
![Page 11: Algorithms - cs.princeton.edu](https://reader031.vdocuments.site/reader031/viewer/2022012016/615a9172315fff046f3c09bd/html5/thumbnails/11.jpg)
• Choose point p with smallest y-coordinate.
• Sort points by polar angle with p.
• Consider points in order, and discard unless that would create a ccw turn.
1
0
4
5
2
11
Graham scan
67
8
10
1112
9
3
![Page 12: Algorithms - cs.princeton.edu](https://reader031.vdocuments.site/reader031/viewer/2022012016/615a9172315fff046f3c09bd/html5/thumbnails/12.jpg)
• Choose point p with smallest y-coordinate.
• Sort points by polar angle with p.
• Consider points in order, and discard unless that would create a ccw turn.
5
67
12
Graham scan
1
0
2
8
10
1112
9
3
4
![Page 13: Algorithms - cs.princeton.edu](https://reader031.vdocuments.site/reader031/viewer/2022012016/615a9172315fff046f3c09bd/html5/thumbnails/13.jpg)
• Choose point p with smallest y-coordinate.
• Sort points by polar angle with p.
• Consider points in order, and discard unless that would create a ccw turn.
5
67
13
Graham scan
8
10
1112
9
1
0
2
3
4
![Page 14: Algorithms - cs.princeton.edu](https://reader031.vdocuments.site/reader031/viewer/2022012016/615a9172315fff046f3c09bd/html5/thumbnails/14.jpg)
• Choose point p with smallest y-coordinate.
• Sort points by polar angle with p.
• Consider points in order, and discard unless that would create a ccw turn.
5
7
14
Graham scan
8
10
1112
9
1
0
2
3
4
6
![Page 15: Algorithms - cs.princeton.edu](https://reader031.vdocuments.site/reader031/viewer/2022012016/615a9172315fff046f3c09bd/html5/thumbnails/15.jpg)
• Choose point p with smallest y-coordinate.
• Sort points by polar angle with p.
• Consider points in order, and discard unless that would create a ccw turn.
1
0
5
7
8
10
1112
2
15
Graham scan
9
3
4
6
![Page 16: Algorithms - cs.princeton.edu](https://reader031.vdocuments.site/reader031/viewer/2022012016/615a9172315fff046f3c09bd/html5/thumbnails/16.jpg)
• Choose point p with smallest y-coordinate.
• Sort points by polar angle with p.
• Consider points in order, and discard unless that would create a ccw turn.
5
7
8
16
Graham scan
1
2
0
10
1112
9
3
4
6
![Page 17: Algorithms - cs.princeton.edu](https://reader031.vdocuments.site/reader031/viewer/2022012016/615a9172315fff046f3c09bd/html5/thumbnails/17.jpg)
• Choose point p with smallest y-coordinate.
• Sort points by polar angle with p.
• Consider points in order, and discard unless that would create a ccw turn.
5
8
17
Graham scan
10
1112
1
0
2
9
3
4
67
![Page 18: Algorithms - cs.princeton.edu](https://reader031.vdocuments.site/reader031/viewer/2022012016/615a9172315fff046f3c09bd/html5/thumbnails/18.jpg)
• Choose point p with smallest y-coordinate.
• Sort points by polar angle with p.
• Consider points in order, and discard unless that would create a ccw turn.
18
Graham scan
10
1112
1
0
5
2
9
3
4
67
8
![Page 19: Algorithms - cs.princeton.edu](https://reader031.vdocuments.site/reader031/viewer/2022012016/615a9172315fff046f3c09bd/html5/thumbnails/19.jpg)
• Choose point p with smallest y-coordinate.
• Sort points by polar angle with p.
• Consider points in order, and discard unless that would create a ccw turn.
10
19
Graham scan
1112
1
0
5
2
9
3
4
67
8
![Page 20: Algorithms - cs.princeton.edu](https://reader031.vdocuments.site/reader031/viewer/2022012016/615a9172315fff046f3c09bd/html5/thumbnails/20.jpg)
• Choose point p with smallest y-coordinate.
• Sort points by polar angle with p.
• Consider points in order, and discard unless that would create a ccw turn.
10
11
20
Graham scan
12
1
0
5
2
9
3
4
67
8
![Page 21: Algorithms - cs.princeton.edu](https://reader031.vdocuments.site/reader031/viewer/2022012016/615a9172315fff046f3c09bd/html5/thumbnails/21.jpg)
• Choose point p with smallest y-coordinate.
• Sort points by polar angle with p.
• Consider points in order, and discard unless that would create a ccw turn.
1
0
5
10
1112
2
21
Graham scan
9
3
4
67
8
![Page 22: Algorithms - cs.princeton.edu](https://reader031.vdocuments.site/reader031/viewer/2022012016/615a9172315fff046f3c09bd/html5/thumbnails/22.jpg)
• Choose point p with smallest y-coordinate.
• Sort points by polar angle with p.
• Consider points in order, and discard unless that would create a ccw turn.
10
11
22
Graham scan
12
1
0
5
6
8
2
9
3
4
7
![Page 23: Algorithms - cs.princeton.edu](https://reader031.vdocuments.site/reader031/viewer/2022012016/615a9172315fff046f3c09bd/html5/thumbnails/23.jpg)
• Choose point p with smallest y-coordinate.
• Sort points by polar angle with p.
• Consider points in order, and discard unless that would create a ccw turn.
23
Graham scan
12
1
0
5
9
10
11
6
2
3
4
7
8
![Page 24: Algorithms - cs.princeton.edu](https://reader031.vdocuments.site/reader031/viewer/2022012016/615a9172315fff046f3c09bd/html5/thumbnails/24.jpg)
• Choose point p with smallest y-coordinate.
• Sort points by polar angle with p.
• Consider points in order, and discard unless that would create a ccw turn.
10
1112
24
Graham scan
1
0
5
67
2
3
9
4
8