Design and Analysis of Algorithms – Chapter 51 Divide and Conquer (III)* Dr. Ying Lu...

6
Design and Analysis of Algorithms – Chapter 5 1 Divide and Conquer (III)* Dr. Ying Lu [email protected] RAIK 283: Data Structures & RAIK 283: Data Structures & Algorithms Algorithms *slides referred to http://www.aw-bc.com/info/levitin http://www.aw-bc.com/info/levitin

Transcript of Design and Analysis of Algorithms – Chapter 51 Divide and Conquer (III)* Dr. Ying Lu...

Page 1: Design and Analysis of Algorithms – Chapter 51 Divide and Conquer (III)* Dr. Ying Lu ylu@cse.unl.edu RAIK 283: Data Structures & Algorithms *slides referred.

Design and Analysis of Algorithms – Chapter 5 1

Divide and Conquer (III)*

Dr. Ying [email protected]

RAIK 283: Data Structures & RAIK 283: Data Structures & AlgorithmsAlgorithms

*slides referred to http://www.aw-bc.com/info/levitinhttp://www.aw-bc.com/info/levitin

Page 2: Design and Analysis of Algorithms – Chapter 51 Divide and Conquer (III)* Dr. Ying Lu ylu@cse.unl.edu RAIK 283: Data Structures & Algorithms *slides referred.

Design and Analysis of Algorithms – Chapter 5 2

Divide and Conquer ExampleDivide and Conquer Example

Closest-pair problemClosest-pair problem• Presentation Slides by Tsvika Klein Presentation Slides by Tsvika Klein

Page 3: Design and Analysis of Algorithms – Chapter 51 Divide and Conquer (III)* Dr. Ying Lu ylu@cse.unl.edu RAIK 283: Data Structures & Algorithms *slides referred.

Design and Analysis of Algorithms – Chapter 5 3

Divide and Conquer ExampleDivide and Conquer Example

Convex-hull problemConvex-hull problem

Application Domain: Application Domain: computer visualization, ray tracing, path finding in computer visualization, ray tracing, path finding in

AI, GIS, visual pattern matching, verification AI, GIS, visual pattern matching, verification methods, etc.methods, etc.

Page 4: Design and Analysis of Algorithms – Chapter 51 Divide and Conquer (III)* Dr. Ying Lu ylu@cse.unl.edu RAIK 283: Data Structures & Algorithms *slides referred.

Design and Analysis of Algorithms – Chapter 5 4

Divide and Conquer ExampleDivide and Conquer Example

Convex-hull problemConvex-hull problem

• Presentation slides by João CombaPresentation slides by João Comba

Page 5: Design and Analysis of Algorithms – Chapter 51 Divide and Conquer (III)* Dr. Ying Lu ylu@cse.unl.edu RAIK 283: Data Structures & Algorithms *slides referred.

Design and Analysis of Algorithms – Chapter 5 5

QuickHull Algorithm QuickHull Algorithm

Inspired by Quicksort, it compute Convex Hull:Inspired by Quicksort, it compute Convex Hull: Identify extreme points Identify extreme points PP11 and and PP22 (part of hull) (part of hull)

Compute upper hull (Lower hull computation is similar):Compute upper hull (Lower hull computation is similar):• find point find point PPmaxmax that is farthest away from line that is farthest away from line PP11PP22

• compute the hull of the points to the left of line compute the hull of the points to the left of line PP11PPmaxmax

• compute the hull of the points to the left of line compute the hull of the points to the left of line PPmaxmaxPP22

P1

P2

Pmax

Page 6: Design and Analysis of Algorithms – Chapter 51 Divide and Conquer (III)* Dr. Ying Lu ylu@cse.unl.edu RAIK 283: Data Structures & Algorithms *slides referred.

Design and Analysis of Algorithms – Chapter 5 6

Efficiency of QuickHull Efficiency of QuickHull algorithmalgorithm

Finding point farthest away from line Finding point farthest away from line PP11PP2 2 can be can be done in linear timedone in linear time

This gives same efficiency as quicksort: This gives same efficiency as quicksort: • Worst caseWorst case: : ΘΘ( ( nn22) ) • Average caseAverage case: : ΘΘ( ( n n log log nn))

Other algorithms for convex hull:Other algorithms for convex hull:• Graham’s scanGraham’s scan• DCHullDCHullalso in also in ΘΘ( ( n n log log nn) )