convex hull

38
Presented by Aabid Shah Divide-and-Conquer, Technique used : Convex Hull by Graham’s Scan Presented by Aabid Amin Shah MSC-IT IST Sem Roll no: 140201 Central University of Kashmir. Sub: Data Structure 1

Transcript of convex hull

Page 1: convex hull

Presented by Aabid Shah

Divide-and-Conquer,Technique used :

Convex Hull by Graham’s Scan

Presented by• Aabid Amin Shah• MSC-IT IST Sem• Roll no: 140201

• Central University of Kashmir.

Sub: Data Structure

1

Page 2: convex hull

Presented by Aabid Shah

Divide-and-Conquer

The most-well known algorithm design strategy:1. Divide instance of problem into two or more

smaller instances

2. Solve smaller instances recursively

3. Obtain solution to original (larger) instance by combining these solutions

2

Page 3: convex hull

Presented by Aabid Shah3

In divide and conquer, method we divide the set of n points in 0(n) time into two subsets, one containing the leftmost [n/2] points, and one containing the right most [n/2] points, recursively compute the convex hull of the subsets, and then combine the hulls in 0(n) time. The running time is described by the familiar recurrence

T(n) =2T(n/2) +o(n), so the divide and conquer method runs in

o(n log n) time.

Page 4: convex hull

Presented by Aabid Shah

Divide-and-Conquer Technique

subproblem 2 of size n/2

subproblem 1 of size n/2

a solution to subproblem 1

a solution tothe original problem

a solution to subproblem 2

a problem of size n

4

Page 5: convex hull

Presented by Aabid Shah

Control Abstraction for Divide and Conquer

Algorithm DAndC( P ) {if Small( P ) then return S( P );else {

divide P into smaller instances P1, P2, …, Pk , k >= 1;

Apply DAndC to each these sub-problems;return Combine(DAndC(P1), DAndC(P1),…,

DAndC(Pk));}

}

5

Page 6: convex hull

Presented by Aabid Shah

Definition of convex Hull Convex hull of set Q of points is the smallest convex polygon P for

which each point of Q is either on boundary of p or inside it. We have a set of points P0,P1,P2….Pn. These are the set of point

and from among them we will choose a subset of points such that when we make a polygon out of it which has minimum sides than all other points lies inside it and these points are on the polygon. This is the simple and cute definition of convex hull . so we have convex hull, we have set of points so for example .we will use graham ‘s scan algorithm to solve this problem .

6

Page 7: convex hull

Presented by Aabid Shah7 Steps of creation of Convex Hull.

Page 8: convex hull

Presented by Aabid Shah

Graham’s scan Algorithm1. let p0 be the point in Q with the minimum y-coordinates or the left most

such point in case of a tie2. let <p1,p2,p3….pn> be the remaining points in Q, sorted by polar angle in

the counter clock wise order around the p0 (if more than one point has same angle, remove all but that is farthest from p0)

3. let s be the a empty stack i.e. top[s]<--04. push (p0,s)5. Push (p1,s)6. Push (p2,s)7. For i = 3 to n8. While the angle formed by points NEXT-TO-TOP(S),TOP(S),and pi makes a non left turn9. Pop (s)10. Push (pi,s)11 return S

Note: When the algorithm terminates stack[s] contains exactly the vertices of Q in the counter clockwise order of their appearance on the boundary.

8

Page 9: convex hull

Presented by Aabid Shah

How to use of Graham’s scan algorithm.1. we take a point with a minimum y coordinate

and if we have multiple such points with y coordinates break the tie with left most of them.

Let p0,p1,p2……pn is the set of q then we sort them by polar angle counter clockwise order and start from p0 then what we do we maintain a stack. Now the top of stack is 0 we push the first three points on it i.e. p0,p1,p2.

Stack topp2p1P0

Polar angle

The polar angle is theta 3> theta 2> theta 1i.e p1 has lowest polar angle then p2,p3..pn

p0 p1

p2

p3pn

9

Page 10: convex hull

Presented by Aabid Shah

Conditions to check 1. Find the next minimum y coordinate or the leftmost such

point in case of a tie.2. Sort them by polar angle in counter clock wise order

around p0 .3. Maintain the stack to push element on it.4. Pop the element if it makes a non left turn angle.5. Join the farthest point to make a convex hull of vertex

pushed on to the stack.

10

Page 11: convex hull

Presented by Aabid Shah11

Page 12: convex hull

Presented by Aabid Shah12

Page 13: convex hull

Presented by Aabid Shah13

Page 14: convex hull

Presented by Aabid Shah14

Page 15: convex hull

Presented by Aabid Shah15

Page 16: convex hull

Presented by Aabid Shah16

Page 17: convex hull

Presented by Aabid Shah17

Page 18: convex hull

Presented by Aabid Shah18

Page 19: convex hull

Presented by Aabid Shah19

Page 20: convex hull

Presented by Aabid Shah20

Page 21: convex hull

Presented by Aabid Shah21

Page 22: convex hull

Presented by Aabid Shah22

Page 23: convex hull

Presented by Aabid Shah23

Page 24: convex hull

Presented by Aabid Shah24

Page 25: convex hull

Presented by Aabid Shah25

Page 26: convex hull

Presented by Aabid Shah26

Page 27: convex hull

Presented by Aabid Shah27

Page 28: convex hull

Presented by Aabid Shah28

Page 29: convex hull

Presented by Aabid Shah29

Page 30: convex hull

Presented by Aabid Shah30

Page 31: convex hull

Presented by Aabid Shah31

Page 32: convex hull

Presented by Aabid Shah32

Page 33: convex hull

Presented by Aabid Shah33

Page 34: convex hull

Presented by Aabid Shah34

Page 35: convex hull

Presented by Aabid Shah35

Page 36: convex hull

Presented by Aabid Shah36

Page 37: convex hull

Presented by Aabid Shah37

That’s all for Convex Hull…..

Page 38: convex hull

Presented by Aabid Shah38