Post on 16-Apr-2017
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
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
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.
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
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
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
Presented by Aabid Shah7 Steps of creation of 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
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
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
Presented by Aabid Shah11
Presented by Aabid Shah12
Presented by Aabid Shah13
Presented by Aabid Shah14
Presented by Aabid Shah15
Presented by Aabid Shah16
Presented by Aabid Shah17
Presented by Aabid Shah18
Presented by Aabid Shah19
Presented by Aabid Shah20
Presented by Aabid Shah21
Presented by Aabid Shah22
Presented by Aabid Shah23
Presented by Aabid Shah24
Presented by Aabid Shah25
Presented by Aabid Shah26
Presented by Aabid Shah27
Presented by Aabid Shah28
Presented by Aabid Shah29
Presented by Aabid Shah30
Presented by Aabid Shah31
Presented by Aabid Shah32
Presented by Aabid Shah33
Presented by Aabid Shah34
Presented by Aabid Shah35
Presented by Aabid Shah36
Presented by Aabid Shah37
That’s all for Convex Hull…..
Presented by Aabid Shah38