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*(n1) 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*(n1)/2 different pairs of points
number Design and Analysis of Algorithms – Chapter 3 33 Brute force closestpair algorithm
a Closest pair
• Problem: find the closest pair among n points in kdimensional 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
 Fall '12
 yinglu
 Algorithms, Graph Theory, Depthfirst search, mark w

Click to edit the document details