1 / 30

Lecture 4: Divide and Conquer III: Other Applications and Examples

Lecture 4: Divide and Conquer III: Other Applications and Examples. Shang-Hua Teng. Integer Multiplication. When do we need to multiply two very large numbers? In Cryptography and Network Security message as numbers encryption and decryption need to multiply numbers.

azuka
Download Presentation

Lecture 4: Divide and Conquer III: Other Applications and Examples

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 4:Divide and Conquer III:Other Applications and Examples Shang-Hua Teng

  2. Integer Multiplication • When do we need to multiply two very large numbers? • In Cryptography and Network Security • message as numbers • encryption and decryption need to multiply numbers

  3. ************ ************ ************ ************ ************ ************ ************ ************ ************ ************ ************ ************ ************ ************ How to multiply 2 n-bit numbers ************************

  4. c a d b X = Y = • MULT(X,Y) • if |X| = |Y| = 1 then doreturn XY • else return Can We do Better? • Divide and Conquer

  5. Complexity • By the Master Theorem: • The Divide and Conquer Tree if n = 1 if n > 1

  6. Can we do better?(Karatsuba 1962) • Gauss Equation • MULT(X,Y) • if |X| = |Y| = 1 then doreturn XY • else • A1= MULT(a,c); A2 = MULT(b,d); • A3= MULT((a+b)(c+d));

  7. Complexity • By the Master Theorem: • The Divide and Conquer Tree if n = 1 if n > 1

  8. Geometry • Points in space • Dimensions • Distances • Subspaces: lines, planes, hyperplanes • Shapes: circles, spheres, cubes, ellipsoids • More complex shapes: convex hulls,… • Axiomization

  9. Distances • Euclidean distance

  10. Computational Geometry • Methods and algorithm design and analysis for geometric problems • Applications: • Computer Graphics • Computer Vision • Geographic information system • Robotics • Scientific simulation and engineering design

  11. Closest Pair Problems • Input: • A set of points P = {p1,…, pn} in two dimensions • Output: • The pair of points pi, pj that minimize the Euclidean distance between them.

  12. Closest Pair Problem

  13. Closest Pair Problem

  14. Divide and Conquer • O(n2) time algorithm is easy • Assumptions: • No two points have the same x-coordinates • No two points have the same y-coordinates • How do we solve this problem in 1 dimensions? • Sort the number and walk from left to right to find minimum gap • Can we apply divide-and-conquer directly?

  15. Quick-Sort --- ish • d=Quick-Sort-ish-Closest-Pair(A,1,n) • Divide • t = Partition(A,1,n,q) • Conquer • d1= Quick-Sort-ish-Closest-Pair(A,1,t) • d2= Quick-Sort-ish-Closest-Pair(A,t+1,n) • Combine • Return min(d1, d2,min(A[t+1..n])-A[t])

  16. Divide and Conquer • Divide and conquer has a chance to do better than O(n2). • Assume that we can find the median in O(n) time!!! • We can first sort the point by their x-coordinates

  17. Closest Pair Problem

  18. Divide and Conquer for the Closest Pair Problem Divide by x-median

  19. Divide L R Divide by x-median

  20. Conquer L R Conquer: Recursively solve L and R

  21. Combination I L R d2 Takes the smaller one of d1 , d2 : d = min(d1 , d2 )

  22. Combination IIIs there a point in L and a point in R whose distance is smaller than d ? L R Takes the smaller one of d1 , d2 : d = min(d1 , d2 )

  23. Combination II • If the answer is “no” then we are done!!! • If the answer is “yes” then the closest such pair forms the closest pair for the entire set • Why???? • How do we determine this?

  24. Combination IIIs there a point in L and a point in R whose distance is smaller than d ? L R Takes the smaller one of d1 , d2 : d = min(d1 , d2 )

  25. Combination IIIs there a point in L and a point in R whose distance is smaller than d ? L R Need only to consider the narrow band O(n) time

  26. Combination IIIs there a point in L and a point in R whose distance is smaller than d ? L R Denote this set by S, assume Sy is sorted list of S by y-coordinate.

  27. Combination II • There exists a point in L and a point in R whose distance is less than d if and only if there exist two points in S whose distance is less than d. • If S is the whole thing, did we gain any thing? • If s and t in S has the property that ||s-t|| <d, then s and t are within 15 position of each other in the sorted list Sy.

  28. Combination IIIs there a point in L and a point in R whose distance is smaller than d ? L R There are at most one point in each box

  29. Closest-Pair • Closest-pair(P) • Preprocessing: • Construct Pxand Pyas sorted-list by x- and y-coordinates • Divide • Construct L, Lx, Lyand R, Rx, Ry • Conquer • Let d1= Closest-Pair(L, Lx, Ly) • Let d2= Closest-Pair(R, Rx, Ry) • Combination • Let d = min(d1 , d2 ) • Construct S and Sy • For each point in Sy, check each of its next 15 points down the list • If the distance is less than d, update the das this smaller distance

  30. Complexity Analysis • Preprocessing takes O(n lg n) time • Divide takes O(n) time • Conquer takes 2 T(n/2) time • Combination takes O(n) time • So totally takes O(n lg n) time

More Related