Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCE350 Algorithms and Data Structure

Similar presentations


Presentation on theme: "CSCE350 Algorithms and Data Structure"— Presentation transcript:

1 CSCE350 Algorithms and Data Structure
Lecture 11 Jianjun Hu Department of Computer Science and Engineering University of South Carolina

2 Announcements Midterm grades will be ready by Next Tuesday
Extra credit: Take home for the exam again Due next Tuesday. Do it independently. You can refer to books. You can get up to 10 points for your exam. New points will be only scored on problems that you did not do it right in last exam.

3 Strassen’s Matrix Multiplication
Brute-Force nxn matrix multiplication needs n3 number multiplications For example, multiplying two 2x2 matrices needs 23=8 multiplications

4 We can Reduce to 7 Multiplications

5 Divide and Conquer Partition the matrix into 4 submtrices with the size n/2xn/2 The above 7-multiplication 18 additions can be used here, but they are n/2xn/2 matrix multiplication and additions now How to calculate the n/2xn/2 matrix multiplication?– recursion! Stop condition, where the matrix size is 1x1. Recurrence for efficiency analysis (based on # multiplication)

6 Solve the Recurrence Solving it by backward substitution for n=2k yields Therefore Count the # of additions which is the same as the complexity based on multiplication

7 Many Improvements Along This Line
For example, Coopersmith and Winograd Getting closer to the theoretic lower bound

8 Closest-Pair Problem by Divide and Conquer
Brute-force algorithm (in Chapter 3) takes time because the distance between all possible pair of points are computed and compared Divide-and-conquer strategy can be used to achieve more efficient algorithm Given n points Assume that they have been sorted in ascending order of their x coordinate. Sorting complexity (mergesort): Then we divide n points into two subsets S1 and S2 of n/2 points by a vertical line x=c. All the points in S1 are located to the left of or on this line and all the points in S2 are located to the right or on this line. Complexity in finding this line:

9 Recursive Algorithm Find the closest pair in S1 and S2 separately, denoting the closest distance in S1 and S2 are d1 and d2. However, min{d1,d2} is not the desired distance between the closest pair among all n points, why? Closest pair may be located in different side of the partitioning line! How to solve this problem?

10 Solution Suppose these n points are also sorted according to their y- coordinate. This can be done in if S1 and S2 were y-sorted. Then we can construct the y-sorted version of points in C1 and C2 (two strips shown in the above figure) in Merge y-sorted version of points in C1 and C2 into a single sorted list, check each element’s distance to constant # of its neighboring elements in If there is any such distance is less than d, update the shortest distance and the closest pair Recursive equation is

11 Convex-Hull Problem Find the smallest convex polygon that contains n points in a plane. Brute-force convex-hull algorithm Divide and Conquer – quickhull Given n points sorted in increasing order of their x-coordinates with ties resolved by increasing order of y coordinates. First, leftmost point and rightmost point must belong to the convex hull Connecting and , we have a vector , which partitions the plane into two semi-planes and the remaining points into left point sets and right point sets.

12 Quickhull The upper/lower parts of the convex hull are called upper/lower hull, which can be constructed in the similar fashion (recursive algorithm)

13 QuickHull Pmax P2 P1 Compute upper hull:
find point Pmax that is farthest away from line P1P2 compute the hull of the points to the left of line P1Pmax compute the hull of the points to the left of line PmaxP2 Compute lower hull in a similar manner Pmax P2 P1

14 Efficiency of QuickHull algorithm
Finding point farthest away from line P1P2 can be done in linear time This gives same efficiency as quicksort: Worst case: Θ( n2) Average case: Θ( n log n) If points are not initially sorted by x-coordinate value, this can be accomplished in Θ( n log n) — no increase in asymptotic efficiency class Other algorithms for convex hull: Graham’s scan DCHull also in Θ( n log n)


Download ppt "CSCE350 Algorithms and Data Structure"

Similar presentations


Ads by Google