Presentation is loading. Please wait.

Presentation is loading. Please wait.

Algorithm design techniques Dr. M. Gavrilova

Similar presentations


Presentation on theme: "Algorithm design techniques Dr. M. Gavrilova"— Presentation transcript:

1 Algorithm design techniques Dr. M. Gavrilova
CPSC 695 Algorithm design techniques Dr. M. Gavrilova

2 Algorithmic Strategies
Incremental Divide-and-conquer Sweep-line/plane Dimension reduction Geometric decomposition

3 Common Algorithm Techniques
Problem A – you know a lower bound Problem B – it is unknown. If we transform A to B by a transformation step that costs less than solving A, then B has the same lower bound as A

4 Convex Hull problem Convex Hull → Sorting Sorting is Ω(n log n)
Let {x1,x2,…,xn} be a set of numbers (any order) Compute in linear time set of points O(xi,xi2) Build the convex hull of these points By scanning points from left to right obtain sorted array. Convex hull is Ω(n log n) 16 9 4 1

5 Incremental – Convex Hull
Let S={p1,p2,…,pn} denote the set of points of CH. First, construct a triangle {p1,p2, p3} Add point pi to CHi-1 (existing) Two cases are possible: pi  CHi-1 – detected in linear time by scanning the points of CHi-1 in clockwise order, pi is always on the right side pi  CHi-1 – add pi to CH in linear time, by scanning points of CHi-1, finding 2 tangential lines from pi to CH. Analysis: O(n2)

6 Convex Hull – optimization
Algorithm can be improved to O(n lg n) by presorting the input according to abscissas of points. Every time a point pi is added: No need to check CHi-1, it is always outside To find the upper tangent, scan the upper chain, removing points that we scanned Lower tangent – same Linear time to construct CH + sorting O(n lg n)

7 Convex Hull – optimization
Algorithm can be improved using the property that the list of points is sorted. If line through Pi intersects CH, the vertex is discarded. Each vertex is discarded only once. Pi Pi-1

8 Divide-and-conquer The half-plane intersection example: result – convex polygon Recursive: Top-down: subdivision to a smaller problem Bottom-up: recursively merging the solution Similar to merge-sort, quick-sort

9 Divide-and-conquer Create binary tree of half-planes
Intersect each half-plane, starting from the leaves, with rectangle R, which contains the resulting polygon (by assumption)  obtain convex polygons Compute intersection of convex polygons, bottom up on the tree

10 Divide-and-conquer

11 Divide-and-conquer complexity
Convex polygon intersection is O(n) T(n) = 2 T(n/2) + cn i is # of steps  T(n) = 2i T(n/2i)+cni T(n) = 2lg n T(n/2lg n) + c n lg n Assume T(n/2lg n) is O(1), when the size of the problem is small T(n) = O(n lg n)

12 Sweep-line (plane-sweep)
Decompose the input into vertical strips Vertical line (sweep-line) allows to compute/maintain some information Sweep-line goes through a number of events Event list is usually represented by the queue The state of the sweep-line is also maintained.

13 Sweep-line example Given a set S of rectangles with sides parallel to the axes, report all their pair-wise intersections O(n2) – for each rectangle, test intersections with others This is worst-case optimal, because there can be that many intersections. However, let’s try to design an output-sensitive algorithm.

14 Sweep-line example Observations:
Sweep-line undergoes changes in its status when it reaches left/right side of a rectangle (along X coordinate) If X projections intersect – does not mean that rectangles intersect. When left endpoint reached – add rectangle. When the sweep-line intersects the rectangles, Y projections of rectangles should be checked for intersection. If they too intersect, then rectangles intersect. When right endpoint is added – remove rectangle. All events can be scheduled in advance!

15 Sweep line – complexity
Initial sorting of interval endpoints O(n lg n) # of events in the queue is 2n Time to process one event – check for Y intersections is O(1) If the total # of intersections is k, then the total complexity is O(n lg n + k)

16 Dimension reduction Typical problem: build a VD for a set of points in the plane. Consider 3D, build a paraboloid, lift/project points (sites) onto the paraboloid Construct half-spaces tangent to paraboloid at those points. Construct intersection of these half-spaces Projection of these intersections down on the plane gives the VD of initial sites.

17 Geometric decomposition
Reduce more complex problem to a subset of simpler problems, i.e. in polygon intersection problem, compute rough intersection first and then proceed to find more precise intersection through more elaborate computational methods.

18 Review Provide principle of work and examples of algorithm strategies:
Incremental Divide-and-conquer Sweep-line/plane Dimension reduction Geometric decomposition


Download ppt "Algorithm design techniques Dr. M. Gavrilova"

Similar presentations


Ads by Google