Introduction to String Matching
Introduction to String Matching
• Exact Matching:
• The goal is to find all exact occurrences of the pattern in the text.
• Example:Text: "abababa"
• Pattern: "aba"
• Output: Positions 0, 2, and 4 (0-based index).
• Approximate Matching:
• The pattern can match the text approximately, allowing mismatches or edits.
• Example: DNA sequence alignment, where "AGCT" may match "AGTT" with one
substitution.
APPLICATIONS OF STRING MATCHING
CHALLENGES IN STRING MATCHING:
• SequentialSearch(array, key):
• for i = 0 to array.length - 1:
• if array[i] == key:
• return i # Return index of key
• return -1 # Key not found
• Advantages:
• Simple to implement.
• Works on both sorted and unsorted data.
• No additional memory required.
• Disadvantages:
• Inefficient for large datasets.
• Requires linear traversal, making it slower compared to other
search algorithms like binary search.
APPLICATIONS:
• Find the two closest points in a set of n points (in the two
dimensional Cartesian plane).
• Brute-force algorithm
• Compute the distance between every pair of distinct points
and return the indexes of the points for which the distance is
the smallest.
• Standard Euclidean distance:
ALGORITHM
CONVEX HULL
• Convex hull is the smallest convex polygon that contain all the points
in the plane.