Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena...

39
Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

Transcript of Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena...

Page 1: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

Convex Hull: Ordering the Points.

Elena Khramtcova

Algorithms and Data Structures.Faculty of Informatics, USI

Spring 2013

Page 2: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

Definition of convex hull (CH)

P – set of n points in the plane,

Problem(CH): Compute CH(P).

Page 3: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

Definition of convex hull (CH)

P – set of n points in the plane,

Problem(CH): Compute CH(P).

CH(P): smallest convex set containing P.

Page 4: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

Definition of convex hull (CH)

P – set of n points in the plane,

Problem(CH): Compute CH(P).

CH(P): smallest convex set containing P.

Page 5: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

Definition of convex hull (CH)

P – set of n points in the plane,

Problem(CH): Compute CH(P).

h – # of hull points

p1

p2p3

p4

p5

p6

p7

Page 6: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

Sorting can be reduced to CH

A – array of n numbers,

Problem: Compute B = sorted A.

(A[3],0)

(A[2],0)

(A[9],0)

(A[6],0)

(A[4],0)

(A[8],0)

(A[1],0)

(A[5],0)

(A[7],0)

Page 7: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

Sorting can be reduced to CH

A – array of n numbers,

Problem: Compute B = sorted A.

Page 8: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

Sorting can be reduced to CH

A – array of n numbers,

Problem: Compute B = sorted A.

Page 9: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

Sorting can be reduced to CH

A – array of n numbers,

Problem: Compute B = sorted A.

p1

p2p3

p4 p5p6

p7

p8

p9

Page 10: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

Sorting can be reduced to CH

A – array of n numbers,

Problem: Compute B = sorted A.

p1

p2p3

p4 p5p6

p7

p8

p9

(B[1],0) ... (B[9],0)

Page 11: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 1: Jarvis’s march/Jarvis’s wrap

1. Find the lowest point p1

2. Do

Find pnext : min.angle withsupporting line

While pnext ! = p1

Time complexity: O(nh)

Page 12: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 1: Jarvis’s march/Jarvis’s wrap

1. Find the lowest point p1

2. Do

Find pnext : min.angle withsupporting line

While pnext ! = p1

Time complexity: O(nh)

p1

Page 13: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 1: Jarvis’s march/Jarvis’s wrap

1. Find the lowest point p1

2. Do

Find pnext : min.angle withsupporting line

While pnext ! = p1

Time complexity: O(nh)

p1

Page 14: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 1: Jarvis’s march/Jarvis’s wrap

1. Find the lowest point p1

2. Do

Find pnext : min.angle withsupporting line

While pnext ! = p1

Time complexity: O(nh)

p1

Page 15: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 1: Jarvis’s march/Jarvis’s wrap

1. Find the lowest point p1

2. Do

Find pnext : min.angle withsupporting line

While pnext ! = p1

Time complexity: O(nh)

p1

p2

Page 16: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 1: Jarvis’s march/Jarvis’s wrap

1. Find the lowest point p1

2. Do

Find pnext : min.angle withsupporting line

While pnext ! = p1

Time complexity: O(nh)

p1

p2

Page 17: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 1: Jarvis’s march/Jarvis’s wrap

1. Find the lowest point p1

2. Do

Find pnext : min.angle withsupporting line

While pnext ! = p1

Time complexity: O(nh)

p1

p2

p3

Page 18: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 1: Jarvis’s march/Jarvis’s wrap

1. Find the lowest point p1

2. Do

Find pnext : min.angle withsupporting line

While pnext ! = p1

Time complexity: O(nh)

p1

p2

p3

p4

Page 19: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 1: Jarvis’s march/Jarvis’s wrap

1. Find the lowest point p1

2. Do

Find pnext : min.angle withsupporting line

While pnext ! = p1

Time complexity: O(nh)

p1

p2

p3

p4p5

Page 20: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 1: Jarvis’s march/Jarvis’s wrap

1. Find the lowest point p1

2. Do

Find pnext : min.angle withsupporting line

While pnext ! = p1

Time complexity: O(nh)

p1

p2

p3

p4p5

p6

Page 21: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 1: Jarvis’s march/Jarvis’s wrap

1. Find the lowest point p1

2. Do

Find pnext : min.angle withsupporting line

While pnext ! = p1

Time complexity: O(nh)

p1

p2

p3

p4p5

p6

p7

Page 22: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 1: Jarvis’s march/Jarvis’s wrap

1. Find the lowest point p1

2. Do

Find pnext : min.angle withsupporting line

While pnext ! = p1

Time complexity: O(nh) p1

p2

p3

p4p5

p6

p7

Page 23: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 2: ...

1. Divide points by avertical line in twoequal parts

2. Compute CH(Pleft) andCH(Pright) recursively

3. Find two bridges

4. Delete all edgesin-between the bridges

Time complexity: O(n log n)

Page 24: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 2: ...

1. Divide points by avertical line in twoequal parts

2. Compute CH(Pleft) andCH(Pright) recursively

3. Find two bridges

4. Delete all edgesin-between the bridges

Time complexity: O(n log n)

Page 25: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 2: ...

1. Divide points by avertical line in twoequal parts

2. Compute CH(Pleft) andCH(Pright) recursively

3. Find two bridges

4. Delete all edgesin-between the bridges

Time complexity: O(n log n)

Page 26: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 2: ...

1. Divide points by avertical line in twoequal parts

2. Compute CH(Pleft) andCH(Pright) recursively

3. Find two bridges

4. Delete all edgesin-between the bridges

Time complexity: O(n log n)

Page 27: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 2: ...

1. Divide points by avertical line in twoequal parts

2. Compute CH(Pleft) andCH(Pright) recursively

3. Find two bridges

4. Delete all edgesin-between the bridges

Time complexity: O(n log n)

Page 28: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 2: ...

1. Divide points by avertical line in twoequal parts

2. Compute CH(Pleft) andCH(Pright) recursively

3. Find two bridges

4. Delete all edgesin-between the bridges

Time complexity: O(n log n)

Page 29: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 2: Divide and Conquer

1. Divide points by avertical line in twoequal parts

2. Compute CH(Pleft) andCH(Pright) recursively

3. Find two bridges

4. Delete all edgesin-between the bridges

Time complexity: O(n log n)

Page 30: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 3: ...

1. Find points r and l

2. Divide the set by rl into Aand B

3. Return HULL(A, l , r)∪HULL(B, r , l)

HULL(A, l , r)if A = lr , return (l , r) else

1. Find z ∈ A: farthest fromlr

2. R – points to the right of lz

3. L – points to the left of zr

4. Return{HULL(L, l , z) ∪ {z}∪HULL(R, z , r)}

Time complexity: O(n2) w.c.,O(n log n) avg.

Page 31: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 3: ...

1. Find points r and l

2. Divide the set by rl into Aand B

3. Return HULL(A, l , r)∪HULL(B, r , l)

l

r

HULL(A, l , r)if A = lr , return (l , r) else

1. Find z ∈ A: farthest fromlr

2. R – points to the right of lz

3. L – points to the left of zr

4. Return{HULL(L, l , z) ∪ {z}∪HULL(R, z , r)}

Time complexity: O(n2) w.c.,O(n log n) avg.

Page 32: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 3: ...

1. Find points r and l

2. Divide the set by rl into Aand B

3. Return HULL(A, l , r)∪HULL(B, r , l)

l

r

HULL(A, l , r)if A = lr , return (l , r) else

1. Find z ∈ A: farthest fromlr

2. R – points to the right of lz

3. L – points to the left of zr

4. Return{HULL(L, l , z) ∪ {z}∪HULL(R, z , r)}

Time complexity: O(n2) w.c.,O(n log n) avg.

Page 33: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 3: ...

1. Find points r and l

2. Divide the set by rl into Aand B

3. Return HULL(A, l , r)∪HULL(B, r , l)

l

r

z

l

r

HULL(A, l , r)if A = lr , return (l , r) else

1. Find z ∈ A: farthest fromlr

2. R – points to the right of lz

3. L – points to the left of zr

4. Return{HULL(L, l , z) ∪ {z}∪HULL(R, z , r)}

Time complexity: O(n2) w.c.,O(n log n) avg.

Page 34: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 3: ...

1. Find points r and l

2. Divide the set by rl into Aand B

3. Return HULL(A, l , r)∪HULL(B, r , l)

z

l

r

HULL(A, l , r)if A = lr , return (l , r) else

1. Find z ∈ A: farthest fromlr

2. R – points to the right of lz

3. L – points to the left of zr

4. Return{HULL(L, l , z) ∪ {z}∪HULL(R, z , r)}

Time complexity: O(n2) w.c.,O(n log n) avg.

Page 35: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 3: ...

1. Find points r and l

2. Divide the set by rl into Aand B

3. Return HULL(A, l , r)∪HULL(B, r , l)

HULL(A, l , r)if A = lr , return (l , r) else

1. Find z ∈ A: farthest fromlr

2. R – points to the right of lz

3. L – points to the left of zr

4. Return{HULL(L, l , z) ∪ {z}∪HULL(R, z , r)}

Time complexity: O(n2) w.c.,O(n log n) avg.

Page 36: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 3: Quickhull

1. Find points r and l

2. Divide the set by rl into Aand B

3. Return HULL(A, l , r)∪HULL(B, r , l)

HULL(A, l , r)if A = lr , return (l , r) else

1. Find z ∈ A: farthest fromlr

2. R – points to the right of lz

3. L – points to the left of zr

4. Return{HULL(L, l , z) ∪ {z}∪HULL(R, z , r)}

Time complexity: O(n2) w.c.,O(n log n) avg.

Page 37: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 4: Heaphull. It does exist!

Uses a kinetic heap w.r.t. a certain “up” direction

Time complexity: O(n log2 n)

Page 38: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

CH algorithm 4: Heaphull. It does exist!

up up

Uses a kinetic heap w.r.t. a certain “up” directionTime complexity: O(n log2 n)

Page 39: Convex Hull: Ordering the Points. - USI Informatics · Convex Hull: Ordering the Points. Elena Khramtcova Algorithms and Data Structures. Faculty of Informatics, USI Spring 2013

Not covered here

I Graham scan

I Chan’s algorithm

I Randomized incremental construction

I 3- and d-dimension