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

Post on 07-Jun-2020

7 views 0 download

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

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).

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.

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.

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

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)

Sorting can be reduced to CH

A – array of n numbers,

Problem: Compute B = sorted A.

Sorting can be reduced to CH

A – array of n numbers,

Problem: Compute B = sorted A.

Sorting can be reduced to CH

A – array of n numbers,

Problem: Compute B = sorted A.

p1

p2p3

p4 p5p6

p7

p8

p9

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)

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)

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

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

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

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

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

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

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

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

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

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

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

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)

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)

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)

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)

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)

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)

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)

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.

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.

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.

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.

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.

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.

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.

CH algorithm 4: Heaphull. It does exist!

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

Time complexity: O(n log2 n)

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)

Not covered here

I Graham scan

I Chan’s algorithm

I Randomized incremental construction

I 3- and d-dimension