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 Shah
3
 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 to
the 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 Shah
7 Steps of creation of Convex Hull.Presented by Aabid Shah
Graham’s scan Algorithm
1. let p0 be the point in Q with the minimum y-coordinates or the left most
such point in case of a tie
2. 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]<--0
4. push (p0,s)
5. Push (p1,s)
6. Push (p2,s)
7. For i = 3 to n
8. While the angle formed by points NEXT-TO-TOP(S),TOP(S),and pi
makes a
non left turn
9. Pop (s)
10. Push (pi,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
top
p2
p1
P0
Polar
angle
The polar angle is theta 3> theta 2> theta 1
i.e p1 has lowest polar angle then p2,p3..pn
p0 p1
p2
p3
pn
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 Shah
11 Presented by Aabid Shah
12 Presented by Aabid Shah
13 Presented by Aabid Shah
14 Presented by Aabid Shah
15 Presented by Aabid Shah
16 Presented by Aabid Shah
17 Presented by Aabid Shah
18 Presented by Aabid Shah
19 Presented by Aabid Shah
20 Presented by Aabid Shah
21 Presented by Aabid Shah
22 Presented by Aabid Shah
23 Presented by Aabid Shah
24 Presented by Aabid Shah
25 Presented by Aabid Shah
26 Presented by Aabid Shah
27 Presented by Aabid Shah
28 Presented by Aabid Shah
29 Presented by Aabid Shah
30 Presented by Aabid Shah
31 Presented by Aabid Shah
32 Presented by Aabid Shah
33 Presented by Aabid Shah
34 Presented by Aabid Shah
35 Presented by Aabid Shah
36 Presented by Aabid Shah
37
That’s all for Convex Hull…..
Presented by Aabid Shah
38 Presented by Aabid Shah

convex hull

  • 1.
    Divide-and-Conquer, Technique used : ConvexHull 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
  • 2.
    Divide-and-Conquer The most-well knownalgorithm 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 Shah
  • 3.
    3  In divideand 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
  • 4.
    Divide-and-Conquer Technique subproblem 2 ofsize n/2 subproblem 1 of size n/2 a solution to subproblem 1 a solution to the original problem a solution to subproblem 2 a problem of size n 4 Presented by Aabid Shah
  • 5.
    Control Abstraction forDivide 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
  • 6.
    Definition of convexHull  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 Shah
  • 7.
    7 Steps ofcreation of Convex Hull.Presented by Aabid Shah
  • 8.
    Graham’s scan Algorithm 1.let p0 be the point in Q with the minimum y-coordinates or the left most such point in case of a tie 2. 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]<--0 4. push (p0,s) 5. Push (p1,s) 6. Push (p2,s) 7. For i = 3 to n 8. While the angle formed by points NEXT-TO-TOP(S),TOP(S),and pi makes a non left turn 9. Pop (s) 10. Push (pi,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
  • 9.
    How to useof 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 top p2 p1 P0 Polar angle The polar angle is theta 3> theta 2> theta 1 i.e p1 has lowest polar angle then p2,p3..pn p0 p1 p2 p3 pn 9 Presented by Aabid Shah
  • 10.
    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 Shah
  • 11.
    11 Presented byAabid Shah
  • 12.
    12 Presented byAabid Shah
  • 13.
    13 Presented byAabid Shah
  • 14.
    14 Presented byAabid Shah
  • 15.
    15 Presented byAabid Shah
  • 16.
    16 Presented byAabid Shah
  • 17.
    17 Presented byAabid Shah
  • 18.
    18 Presented byAabid Shah
  • 19.
    19 Presented byAabid Shah
  • 20.
    20 Presented byAabid Shah
  • 21.
    21 Presented byAabid Shah
  • 22.
    22 Presented byAabid Shah
  • 23.
    23 Presented byAabid Shah
  • 24.
    24 Presented byAabid Shah
  • 25.
    25 Presented byAabid Shah
  • 26.
    26 Presented byAabid Shah
  • 27.
    27 Presented byAabid Shah
  • 28.
    28 Presented byAabid Shah
  • 29.
    29 Presented byAabid Shah
  • 30.
    30 Presented byAabid Shah
  • 31.
    31 Presented byAabid Shah
  • 32.
    32 Presented byAabid Shah
  • 33.
    33 Presented byAabid Shah
  • 34.
    34 Presented byAabid Shah
  • 35.
    35 Presented byAabid Shah
  • 36.
    36 Presented byAabid Shah
  • 37.
    37 That’s all forConvex Hull….. Presented by Aabid Shah
  • 38.
    38 Presented byAabid Shah