Download presentation

Presentation is loading. Please wait.

Published byEmily Tate Modified over 6 years ago

1
Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Dr. Sumanta Guha Slide Sources: CLRS “Intro. To Algorithms” book website (copyright McGraw Hill) adapted and supplemented

2
CLRS “Intro. To Algorithms” Ch. 33: Computational Geometry

3
If p 1 = (x 1, y 1 ) and p 2 = (x 2, y 2 ) then p 1 p 2 = x 1 x 2 = x 1 y 2 – x 2 y 1 * y 1 y 2 If p 1 p 2 > 0, then p1 is clockwise from p2 (turning around the origin); if p 1 p 2 < 0, then p1 is counterclockwise from p2; If p 1 p 2 = 0, then p1 and p2 are collinear (pointing in either same or opposite directions) * The cross product is actually a 3D vector whose magnitude is |x 1 y 2 – x 2 y 1 |. Here we simplify for 2D.

5
If DIRECTION(p i, p j, p k ) > 0, then p j – p i is a left turn from p k – p i around p i < 0, then p j – p i is a right turn from p k – p i around p i = 0, then p j – p i and p k – p i are collinear

7
How?!

10
Eliminate the polar co-ordinate sort part of Graham’s scan by modifying it to scan the vertices sorted from left to right. Otherwise, the underlying principle, data structures, etc. remain the same. Comment : This modification of Graham’s scan was made by Andrew (1979) and is often called the Monotone Chain algorithm.

11
Jarvis’s march is output-sensitive!

12
Closest Pair by Divide-and-Conquer Following slides are copied from Dariusz Kowalski (www.csc.liv.ac.uk/~darek/COMP523/le cture5.ppt)

13
Lecture 5: Divide and Conquer, cont. (Dariusz Kowalski) 13 Solution Preprocessing: Sort points according to the first coordinate (obtain horizontal list H) and according the second coordinate (obtain vertical list V) Main Algorithm: Partition list H input into halves in linear time (draw vertical line L containing medium point) Solve the problem for each half of the input separately, obtaining two pairs of closest points; let be the smallest distance from the obtained ones Find if there is a pair which has distance smaller than - if yes then find the smallest distance pair

14
14 Main difficulty Find if there is a pair which has distance smaller than - if yes then find the smallest distance pair How to do it in linear time? Lecture 5: Divide and Conquer, cont. (Dariusz Kowalski)

15
15 Closest pair in the strip 1. Find a sublist P of V containing all points with a distance at most from the line L - in linear time 2. For each element in P check its distance to the next 8 elements and remember the closest pair ever found L Lecture 5: Divide and Conquer, cont. (Dariusz Kowalski)

16
16 Why to check only 8 points ahead? 1. Partition the strip into squares of length /2 as shown in the picture. 2. Each square contains at most 1 point - by definition of . 3. If there are at least 2 squares between points then they can not be the closest points. 4. There are at most 8 squares to check. /2/2 L /2/2 /2/2 /2/2 /2/2 /2/2 Lecture 5: Divide and Conquer, cont. (Dariusz Kowalski)

17
Problems Ex. 33.3-2 Ex. 33.3-4 Ex. 33.3-5 Ex. 33.3-6 Ex. 33.4-3 Ex. 33.4-4 Ex. 33.4-5 Prob. 33-1

Similar presentations

© 2021 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google