Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8018541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:09:08+00:00 2026-06-04T21:09:08+00:00

Approximate string matching is not a stranger problem. I am learning and trying to

  • 0

Approximate string matching is not a stranger problem.

I am learning and trying to understand how to solve it. I even now don’t want to get too deep into it and just want to understand the brute-force way.

In its wiki page (Approximate string matching), it says

A brute-force approach would be to compute the edit distance to P (the pattern) for all substrings of T, and then choose the substring with the minimum distance. However, this algorithm would have the running time O(m * n^3), n is the length of T, m is the length of P

Ok. I understand this statement in the following way:

  1. We find out all possible substrings of T
  2. We compute the edit distance of each pair of strings {P, t1}, {P, t2}, …
  3. We find out which substring has the shortest distance from P and this substring is the answer.

I have the following question:

a. I can use two for-loop to get all possible substrings and this requires O(n^2). So when I try to compute the edit distance of one substring and the patter, does it need O(n*m)? Why?

b. How exactly do I compute the distance of one pair (one substring and the patter)? I know I can insert, delete, substitute, but can anyone give me a algorithm that do just the calculation for one pair?

Thanks


Edit

Ok, I should use Levenshtein distance, but I don’t quite understand its method.

Here is part of the code

for j from 1 to n
{
    for i from 1 to m
    {
      if s[i] = t[j] then  
        d[i, j] := d[i-1, j-1]       // no operation required
      else
        d[i, j] := minimum
                   (
                     d[i-1, j] + 1,  // a deletion
                     d[i, j-1] + 1,  // an insertion
                     d[i-1, j-1] + 1 // a substitution
                   )
    }
  }

So, assume I am now comparing {"suv", "svi"}.

So 'v' != 'i', then I have to see three other pairs:

  1. {"su", "sv"}
  2. {"suv", "sv"}
  3. {"su", "svi"}

How can I understand this part? Why I need to see these 3 parts?

Does the distance between two prefixes mean that we need distance number of changes in order to make the two prefixes (or strings) equal?

So, let’s take a look at {"su", "sv"}. We can see that distance of {"su", "sv"} is 1. Then how can {"su", "sv"} become {"suv", "svi"} by just adding 1? I think we need to insert ‘v’ into “su” and ‘v’ into “sv” and then substitute the last ‘i’ with ‘v’, which has 3 operations involved, right?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:09:09+00:00Added an answer on June 4, 2026 at 9:09 pm

    The standard way of measuring the edit distance between two strings is called Levenshtein distance – the wikipedia page contains pseudocode for the algorithm.

    As for your edit: You need to look at {"su", "sv"} because it is possible that the best way to change "suv" into "svi" is to replace the last v by i, whose cost will come on top of the cost for changing "su" to "sv". Or, it could be that the best way is to change "suv" into "sv" somehow and then add an i. Or, it could be that the best way is to first delete the v from "suv" and then change "su" into "svi". The first way turns out to be best (or as good as the other options) in this case. The edit distance is indeed 2, and the operations are to change the u into a v and the v into an i.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my work I have with great results used approximate string matching algorithms such
I have been trying to approximate e using series representation to get as many
I have just written some code for approximate string matching. I would like to
I am seeking for a C library that does approximate string matching. Calculating Levenshtein
Which sorting algorithm can be used to get nearer and approximate matching list with
I am working with Sphinx and would like to implement string sorting. I understand
I'm trying to approximate Single Sign on. Currently, the most workable solution involves the
I have a list of keywords I'm trying to find in a text string.
I have N strings that I want to divide lexicographic into M even-sized buckets
i'm having a string(MyString) of length 9700000(approximately). and a for loop to get substring

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.