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.
Image of page 18
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.
Image of page 19
Image of page 20
Exercise 3.2 Finding the two closest points in a set of n points
Image of page 21
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
Image of page 22
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
Image of page 23
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.
Image of page 24
Pseudocode below computes the distance between the two closest points:
Image of page 25
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.
Image of page 26
Image of page 27

You've reached the end of your free preview.

Want to read all 32 pages?

  • Fall '19

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors