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

Post on 17-Dec-2015

212 views 0 download

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

Design and Analysis of Algorithms – Chapter 5 1

Divide and Conquer (III)*

Dr. Ying Luylu@cse.unl.edu

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

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

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.

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

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

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) )