Lec09_10_Divide&Conquer

Lec09_10_Divide&Conquer - Algorithm Design Strategy...

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon
Algorithm Design Strategy Divide and Conquer Revisit Notes on Brute-force approach
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
More example by using Divide and Conquer method Introduction of D&C Approach Finding closest pair of points Quicksort Matrix Multiplication Algorithm Large Integer Multiplication Convex Hull-problem
Background image of page 2
Divide and Conquer Approach Concept: - D&C is a general strategy for algorithm design. It involves three steps: (1) Divide an instance of a problem into one or more smaller instances (2) Conquer (solve) each of the smaller instances. Unless a smaller instance is sufficiently small, use recursion to do this (3) If necessary, combine the solutions to the smaller instances to obtain the solution to the original instances (e.g., Mergesort) Approach: - Recursion (Top-down approach)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Example 1 Binary search in a sorted array with size n Worst case time complexity in the recursive binary search: W(n) = W(n/2) + 1 W(1) = 1 Solve the recurrence, and obtain: W(n) = lg(n) +1 Θ (lg n)
Background image of page 4
Example 2 Finding the closest pair of points - Task: solve the problem of finding the closest pair of points in a set of points. The set consists of points in two dimensional plane defined by both an X and a Y coordinate. - Given a set P of N points, find p. q P, such that the distance d(p, q) is minimum - Application: - traffic control systems: A system for controlling air or sea traffic might need to know which two vehicles are too close in order to detect potential collisions. - Computational geometry
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Example 2 Finding the closest pair of points - The "closest pair" refers to the pair of points in the set that has the smallest Euclidean distance, Distance between points p1=(x1,y1) and p2=(x2,y2) - If there are two identical points in the set, then the closest pair distance in the set will obviously be zero. 2 2 1 2 2 1 2 1 ) ( ) ( ) , ( y y x x p p D - + - =
Background image of page 6
Example 2 (brute-force approach) Find the two closest points in a set of Find the two closest points in a set of n n points (in the two- points (in the two- dimensional Cartesian plane). dimensional Cartesian plane). Brute-force algorithm Brute-force algorithm Compute the distance between every pair of distinct points Compute the distance between every pair of distinct points and return the indexes of the points for which the distance is and return the indexes of the points for which the distance is the smallest. the smallest.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Closed pair problem (Brute-force approach)
Background image of page 8
Example 2 Finding the closest pair of points - Brute-force algorithm: Find all the distances D(p, q) and find the minimum distance Time complexity: O(n 2 )
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Notes on Brute-force approach A straightforward approach, usually based directly on the A straightforward approach, usually based directly on the problem’s statement and definitions of the concepts involved problem’s statement and definitions of the concepts involved Examples: Examples: Computing Computing an an ( ( a a > 0, > 0, n n a nonnegative integer) a nonnegative integer) Computing Computing n n !
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 48

Lec09_10_Divide&Conquer - Algorithm Design Strategy...

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online