0% found this document useful (0 votes)
16 views20 pages

Lectur 7 Max-Min Problem

Uploaded by

Vikash Agrawal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views20 pages

Lectur 7 Max-Min Problem

Uploaded by

Vikash Agrawal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Divide and Conquer

• divide and conquer algorithms solve problems by dividing them into instances, solving
each instance recursively and merging the corresponding results to a complete
solution.
Properties:
• all instances have exactly the same structure as the original problem
• can be solved independently from each other, and
• so can easily be distributed over a number of parallel processes or threads

• How is it different from dynamic programming?


• Break down into optimal subproblems.
• Store the solutions for smaller subproblems
• Generally more efficient
Max-Min problem
Max-Min problem is to find a maximum and minimum element from the given array.

Solve using divide and conquer approach


Three stages

•If a1 is the only element in the array, a1 is the maximum and minimum.

•If the array contains only two elements a1 and a2, compare them to find the minimum
and maximum.

•If there are more than two elements, the algorithm divides the array from the middle and
creates two sub-problems.
• Both sub-problems are treated as an independent problem and
• Divide into sub-problems until sub-problem size becomes one or two.

Using maximum and minimum of sub-problems, find the maximum and minimum of the
problem
Continue bottom up till the solution is found
Find max and min for the sequence
<33, 11, 44, 55, 66, 22>

Green – max
Blue - min
Convex hull
A polygon is defined as a closed shape with more than two sides or line segments.
Convex Polygon: A convex is a polygon in which any line joining two points within
the polygon lies within the polygon

Convex Hull of a set Q of points is the smallest convex polygon P, for which each
point in Q is either on the boundary of P or in its interior.

A convex hull is the smallest convex polygon that contains a given set of points.
A polygon is called complex if the angle between adjacent sides is less than 180
degrees.
The convex hull problem.

Find the smallest polygon P such that all the points of set Q are either on the
boundary of P or inside P
Process
• Sort the points in increasing order of their x coordinates, resolve ties by sorting on y
coordinates
• Recursively Divide the set of points into two sets till each partition has 3 or less
points
• Construct the convex hulls by joining all points in each subset
• Recursive compute convex hulls by joining all points in each subset
• Merge the points till two hulls are left, HA and HB
• Remove partitions in the reverse order in which they were placed
• Merge using the extreme points of each polygon
• Merge the convex hulls, HA and HB
• Find the upper most tangent and merge the points
• Find the lower most tangent and merge the points
Example
• S: (2,12), (4,17), (10,19), (12,15), (15,19), (7,20),(18,20), (16,10), (18,2), (14,7), (20,11), (8,9), (4,6) and
(9,1).
Step 1: Sort
P1(2,12),
P2(4,6),
P3(4,17),
P4(7,20),
P5(8,9),
P6(9,1),
P7(10,19),
P8(12,15),
P9(14,7),
P10(15,19),
P11(16,10),
P12(18,2) ,
P13(18,20),
Example
• S: (2,12), (4,17), (10,19), (12,15), (15,19), (7,20),(18,20), (16,10), (18,2), (14,7), (20,11), (8,9), (4,6) and
(9,1).
Step 2: Recursively Divide
P1(2,12),
P2(4,6),
P3(4,17),
P4(7,20),
P5(8,9),
P6(9,1),
P7(10,19),
P8(12,15),
P9(14,7),
P10(15,19),
P11(16,10),
P12(18,2) ,
P13(18,20),
Example
• S: (2,12), (4,17), (10,19), (12,15), (15,19), (7,20),(18,20), (16,10), (18,2), (14,7), (20,11), (8,9), (4,6) and
(9,1).
Step 2: Recursively Divide
P1(2,12),
P2(4,6),
P3(4,17),
P4(7,20),
P5(8,9),
P6(9,1),
P7(10,19),
P8(12,15),
P9(14,7),
P10(15,19),
P11(16,10),
P12(18,2) ,
P13(18,20),
Example
• S: (2,12), (4,17), (10,19), (12,15), (15,19), (7,20),(18,20), (16,10), (18,2), (14,7), (20,11), (8,9), (4,6) and
(9,1).
Step 2: Recursively Divide
P1(2,12),
P2(4,6),
P3(4,17),
P4(7,20),
P5(8,9),
P6(9,1),
P7(10,19),
P8(12,15),
P9(14,7),
P10(15,19),
P11(16,10),
P12(18,2) ,
P13(18,20),
Example
• S: (2,12), (4,17), (10,19), (12,15), (15,19), (7,20),(18,20), (16,10), (18,2), (14,7), (20,11), (8,9), (4,6) and
(9,1).
Step 3: Recursively join the points by removing partitions in the reverse order in which they were placed
P1(2,12),
P2(4,6),
P3(4,17),
P4(7,20),
P5(8,9),
P6(9,1),
P7(10,19),
P8(12,15),
P9(14,7),
P10(15,19),
P11(16,10),
P12(18,2) ,
P13(18,20),
Example
• S: (2,12), (4,17), (10,19), (12,15), (15,19), (7,20),(18,20), (16,10), (18,2), (14,7), (20,11), (8,9), (4,6) and
(9,1).
Step 3: Recursively join the points by removing partitions in the reverse order in which they were placed
P1(2,12),
P2(4,6),
P3(4,17),
P4(7,20),
P5(8,9),
P6(9,1),
P7(10,19),
P8(12,15),
P9(14,7),
P10(15,19),
P11(16,10),
P12(18,2) ,
P13(18,20),
Example
• S: (2,12), (4,17), (10,19), (12,15), (15,19), (7,20),(18,20), (16,10), (18,2), (14,7), (20,11), (8,9), (4,6) and
(9,1).
Step 3: Recursively join the points by removing partitions in the reverse order in which they were placed
P1(2,12),
P2(4,6),
P3(4,17),
P4(7,20),
P5(8,9),
P6(9,1),
P7(10,19),
P8(12,15),
P9(14,7),
P10(15,19),
P11(16,10),
P12(18,2) ,
P13(18,20),
Example
• S: (2,12), (4,17), (10,19), (12,15), (15,19), (7,20),(18,20), (16,10), (18,2), (14,7), (20,11), (8,9), (4,6) and (9,1).
Step 4: Construct the convex hulls by joining all points in each subset: Remove the partition in reverse
order
P1(2,12),
P2(4,6),
P3(4,17),
P4(7,20),
P5(8,9),
P6(9,1),
P7(10,19),
P8(12,15),
P9(14,7),
P10(15,19),
P11(16,10),
P12(18,2) ,
P13(18,20),
Example
• S: (2,12), (4,17), (10,19), (12,15), (15,19), (7,20),(18,20), (16,10), (18,2), (14,7), (20,11), (8,9), (4,6) and (9,1).
Step 4: Construct the convex hulls by joining all points in each subset: Remove the partition in reverse
order
P1(2,12),
P2(4,6),
P3(4,17),
P4(7,20),
P5(8,9),
P6(9,1),
P7(10,19),
P8(12,15),
P9(14,7),
P10(15,19),
P11(16,10),
P12(18,2) ,
P13(18,20),
Example
• S: (2,12), (4,17), (10,19), (12,15), (15,19), (7,20),(18,20), (16,10), (18,2), (14,7), (20,11), (8,9), (4,6) and (9,1).
Step 4: Construct the convex hulls by joining all points in each subset: Remove the partition in reverse
order
P1(2,12),
P2(4,6),
P3(4,17),
P4(7,20),
P5(8,9),
P6(9,1),
P7(10,19),
P8(12,15),
P9(14,7),
P10(15,19),
P11(16,10),
P12(18,2) ,
P13(18,20),
• Step 5:
Find upper most
tangent
Find lower most
tangent

You might also like