algorithms - cs.princeton.edu

24
Algorithms, 4 th Edition · Robert Sedgewick and Kevin Wayne · Copyright © 2002–2011 · September 24, 2011 8:59:25 AM Algorithms F 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 AY N E GRAHAM SCAN DEMO

Upload: others

Post on 04-Oct-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Algorithms - cs.princeton.edu

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

• 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

• 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

• 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

• 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

• 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

• 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

• 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

• 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

• 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

• 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

• 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

• 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

• 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

• 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

• 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

• 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

• 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

• 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

• 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

• 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

• 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

• 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

• 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