Home > CS3310: Design and Analysis of Algorithms > Brute Force: Closest-Pair ProblemBrute Force: Closest-Pair Problem
Find two closest points in a set of n points in a two-dimensional Cartesian plane.
Brute Force Solution:
Q: What is the basic operation?
A: Calculating the distance between two points.
e.g., suppose you want to find the distance between Point A and Point B.
P_{AB} = \sqrt{ (x_a - x_b)^2 (y_a - y_b)^2 }
The basic operation is sqrt.
Q: How many times does basic operation execute?
A:
We know it depends on the # of different pairs of points.
More formally:
We can use the product rule (CS1300) to get:
C(n) = \frac{n \times (n-1)}{2}
We divide by two to avoid double-counting of A \leftrightarrow B and B \leftrightarrow A
Thus, this algorithm is in O(n^2)
Strengths
Weaknesses
A brute force solutoin to a problem involving search for an element with a special property, usually among combinatorial objects such as permutations, combinations, or subsets of a set.
TODO Method
On Performance: Exactness is Costly
- Runs in realistic time only on very small instances.
- In some cases, there are better alternatives.
- In many cases, exhaustive search or a variation is the only known way to get an exact solution.
Given n cities with known distances between each pair, find the shortest tour that passes through all the cities exactly once before returning to the starting city.
TODO Example
There are (n-1)! ways to traverse this.
Find most valuable subset of items that fit into the knapsack.
The exhaustive solution is a n! solution!