{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture topic-BruteForce

# Design and analysis of algorithms chapter 3 31

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: xi − yi ) 2 i =1 2 d= k ∑ ( xi − yi ) 2 i =1 • How many different pairs of points? Design and Analysis of Algorithms – Chapter 3 31 Principle of counting: Product Rule Rule a The Product Rule • Suppose that a procedure can be broken down into a sequence of Suppose two tasks. If there are n1 ways to do the first task and for each of two these ways of doing the first task, there are n 2 ways to do the second these task, then there are n1n2 ways to do the procedure. task, Design and Analysis of Algorithms – Chapter 3 32 Principle of counting: Product Rule Rule a The Product Rule • Suppose that a procedure can be broken down into a sequence of Suppose two tasks. If there are n1 ways to do the first task and for each of two these ways of doing the first task, there are n 2 ways to do the second these task, then there are n1n2 ways to do the procedure. task, a Calculation • Applying the product rule, there are n*(n-1) pairs among n points Applying • Considering (a, b) and (b, a) as the same, we divide the above Considering number by 2 and thus, there are n*(n-1)/2 different pairs of points number Design and Analysis of Algorithms – Chapter 3 33 Brute force closest-pair algorithm a Closest pair • Problem: find the closest pair among n points in k-dimensional space • Algorithm: Compute distance between each pair of points and Compute identify the pair resulting in the shortest distance identify • Basic operation: d= k ∑ ( xi − yi ) 2 i =1 2 d=...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online