Presentation is loading. Please wait.

Presentation is loading. Please wait.

COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin.

Similar presentations


Presentation on theme: "COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin."— Presentation transcript:

1 COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin

2 CSE @ UTA COMPUTATIONAL GEOMETRY Data is defined as points, lines, surfaces, polygons etc. Convex Non-convex  Convex Polygon has every in degree less than 180  Non Convex Polygon may have one or more in degrees greater than 180

3 CSE @ UTA Computational Geometry – Position of Point Problem: To determine whether a given point lies outside or inside a given polygon. Answer: Yes if the point lies inside the polygon, No otherwise Solution: Draw a line along the X –axis from the point in one direction i.e. the line can have a increasing as well as decreasing X – axis. If the line thus drawn intersects ONLY once with any edge of the polygon then the point lies inside the polygon else it lies outside the polygon

4 CSE @ UTA Computational Geometry – Position of Point (..contd.) Example: _ _ _ _ _ _ _ _ _ __ _ _.P The above point intersects only once with an edge of the polygon hence it lies inside polygon

5 CSE @ UTA Computational Geometry – Position of Point (…contd) Example: _ _.P___ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.P _ _ (a) (b) (a)The line extending from point P intersects the polygon edges more than once (twice in this Example), hence P lies outside the polygon (b) In case of Non Convex Polygon, a given point lies inside the polygon if the line segment Extending from it intersects the polygon edges an ODD number of times else it lies outside

6 CSE @ UTA Convex Hulls Informally,Convex hull is defined as an Convex Polygon whose vertices come from the original points and its perimeter encapsulates all the points. Definition:The Convex Hull of a set Q of points is the smallest convex polygon P, for which each point in Q is either on the boundary of P or in its interior. If there is a plane Q, consisting of nails sticking out from a board. Then the Convex Hull of Q can be thought of the shape formed by a tight rubber band that surrounds all the nails

7 CSE @ UTA Convex Hulls Example of an Convex Hull Po P1 P3 P10 P12 P11 P9 P6 P7 P8 P5 P4 P2

8 CSE @ UTA Convex Hull – Jarvis March Convex Hull  Jarvis March  Graham Scan Jarvis March: Computation of Convex Hull  For Every Point, join with all the original points and for the resulting line segments compute the angle with respect to origin, the smallest angle thus obtained gives the next point.  Running time is O(n 2 )  Actual running time is O(n*h), where h is the number of points on the convex hull.

9 CSE @ UTA Convex Hull – Jarvis March (…contd.) Example of Jarvis March P1 P9 P7 P2 P6 P3 P5 P4 P8 P0 Jarvis March’s algorithm starts from P0 ie the anchor point. Then it wraps the next outer point and makes this as the new anchor point and repeats the procedure for the rest of the points……. Till every point is wrapped inside.

10 CSE @ UTA Convex Hull – Graham Scan Graham Scan – Computation of Convex Hull  Sort angles in counter clock wise direction  Create Polygon by connecting points in sorted order  Thereby a Non Convex Polygon results( Could also be convex)  Now wrap the above Non – Convex polygon by a convex polygon.

11 CSE @ UTA Convex Hull – Graham Scan (…contd.) Algorithm (Package Wrapping or Gift Wrapping)  Start from bottom i.e. left most point going counter clockwise  Join with the next point in the counter clock wise direction so long as the resulting line segment makes left turns (>180) it will be included.  If the line segment forms an angle <180, then discard current path, walk back to the previous points and join successfully with new points and measure the resulting angle.  Running time is O(nlogn), as walking around takes 2n, since each is traversed only twice in the worst case and once the edge is dropped it is never again considered and the sorting of angles takes O(logn), hence the resulting running time is O(nlongn)

12 CSE @ UTA Convex Hull – Graham Scan (…contd.) As shown, Grahams starts from a point (p0) and calculates all the angles it makes to all the points and sorts the angles in an order

13 CSE @ UTA Convex Hull – Graham Scan (…contd.) It selects the point with the least angle and starts traversing (P0-P1). Then P1 to P2 & from P2 to P3 it realizes that it takes a right turn, so it backtracks and selects P1 – P3 directly, it being shorter

14 CSE @ UTA Convex Hull – Graham Scan (…contd.) The algorithm continues, based on the above mentioned conditions till it reaches back to the initial point. Hence forming the Convex Hull as shown:

15 CSE @ UTA Convex Hull – Graham Scan (…contd.)

16

17 Once the initial point is reached the algorithm self terminates, and the Convex Hull is formed.

18 CSE @ UTA Multiplication of Large Numbers Matrix Multiplication: Traditional method Takes O(n 2 ) time Traditional Method Given two matrices A and B compute their product. A B

19 CSE @ UTA Multiplication of Large Numbers (…contd.)  Divide the two arrays into two parts each, A into A l and A r, and B into B l and B r.  A l A r  B l B r

20 CSE @ UTA Multiplication of Large Numbers (…contd.) A = A l 10 n/2 + A r B = B l 10 n/2 + B r A.B = (A l 10 n/2 + A r )( B l 10 n/2 + B r ) = A l B l 10 n + A l B r 10 n/2 + A r B l 10 n/2 + A r B r Time Complexity : T(n) T(n) = 4T(n/2) + O(n) = O(n 2 )

21 CSE @ UTA Multiplication of Large Numbers (…contd.) The goal is to reduce the time complexity from O(n 2 ). The intuition is that since we use recursion in our multiplication of the equation, if we can reduce the number of calls to the recursive function Multiply(x,y) the overall complexity of the problem can be significantly reduced.

22 CSE @ UTA Multiplication of Large Numbers (…contd.) Consider the equation from the previous slide: A l B l 10 n + A l B r 10 n/2 + A r B l 10 n/2 + A r B r This equation can be re-arranged as under: A l B l 10 n/2 + (A l B r + A r B l )10 n/2 + A r B r Now, we call the multiplication function Mult(X,Y) recursively as follows:  X = Mult(A l,B l )  Y = Mult(A r,B r )  P = A l + A r  Q = B l + B r

23 CSE @ UTA Multiplication of Large Numbers (…contd.) Z = Mult(p,q) U = Z – X – Y Return: X10n + U10n/2 + Y, Where X10n = A l B l 10 n/2 U10n/2 = (A l B r + A r B l )10 n/2 Y = A r B r Thus, in this approach we have replaced four calls to the Mult(X,Y) function in the traditional method to three calls.

24 CSE @ UTA Multiplication of Large Numbers (…contd.) Thus the resulting time complexity is: T(n) = 3T(n/2) + O(n) = 3[3T(n/2 2 ) + n/2] + n = 3 2 T(n/2 2 ) + 3n/2 + n = nlog 2 3 = n 1.7


Download ppt "COMPUTATIONAL GEOMETRY AND MATRIX MULTIPLICATION Mohammed Zeeshan Farooqui Minhaj Uddin."

Similar presentations


Ads by Google