Characters called the text and a string of m

• No School
• AA 1
• 32

This preview shows page 18 - 27 out of 32 pages.

characters called the text and a string of m characters (m ≤ n) called the pattern, find a substring of the text that matches the pattern.
A brute-force algorithm for the string-matching problem is quite obvious: Align the pattern against the first m characters of the text start matching the corresponding pairs of characters from left to right Until either all the m pairs of the characters match (then the algorithm can stop) Or a mismatching pair is encountered.
Exercise 3.2 Finding the two closest points in a set of n points
Closest-Pair Problem Find the two closest points in a set of n points Points can represent physical objects as airplanes or post offices as well as database records, statistical samples, DNA sequences, and so on An air-traffic controller might be interested in two closest planes as the most probable collision candidates
Closest-Pair Problem Consider the two-dimensional case of the closest-pair problem points in question are specified in a standard fashion by their (x, y) Cartesian coordinates the distance between two points p i (x i , y i ) and p j (x j , y j ) is the standard Euclidean distance
Closest-Pair Problem The brute-force approach: compute the distance between each pair of distinct points and find a pair with the smallest distance. Of course, we do not want to compute the distance between the same pair of points twice. To avoid doing so, we consider only the pairs of points (p i , p j ) for which i < j.
Pseudocode below computes the distance between the two closest points:
Fake Coins A stack of fake coins There are n stacks of n identical-looking coins. All of the coins in one of these stacks are counterfeit, while all the coins in the other stacks are genuine.

You've reached the end of your free preview.

Want to read all 32 pages?

• Fall '19

What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern