Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A first idea to speed up the computation (works if <code>|e-b|</code> is not too large):</p> <ul> <li><p>Question: how much can the Levestein distance change when we compare <code>s</code> with <code>n</code> and then with <code>n+1</code>? </p></li> <li><p>Answer: not too much! </p></li> </ul> <p>Let's see the dynamic-programming tables for <code>s = 12007</code> and two consecutive <code>n</code></p> <pre><code>n = 12296 0 1 2 3 4 5 1 0 1 2 3 4 2 1 0 1 2 3 3 2 1 1 2 3 4 3 2 2 2 3 5 4 3 3 3 3 </code></pre> <p>and </p> <pre><code>n = 12297 0 1 2 3 4 5 1 0 1 2 3 4 2 1 0 1 2 3 3 2 1 1 2 3 4 3 2 2 2 3 5 4 3 3 3 2 </code></pre> <p>As you can see, <strong>only the last column changes</strong>, since <code>n</code> and <code>n+1</code> have the same digits, except for the last one.</p> <p>If you have the dynamic-programming table for the edit-distance of <code>s = 12001</code> and <code>n = 12296</code>, you already have the table for <code>n = 12297</code>, you just need to update the last column!</p> <p>Obviously if <code>n = 12299</code> then <code>n+1 = 12300</code> and you need to update the last 3 columns of the previous table.. but this happens just once every 100 iteration.</p> <p>In general, you have to</p> <ul> <li>update the last column on every iterations (so, length(s) cells)</li> <li>update the second-to-last too, once every 10 iterations</li> <li>update the third-to-last, too, once every 100 iterations</li> </ul> <p>so let <code>L = length(s)</code> and <code>D = e-b</code>. First you compute the edit-distance between <code>s</code> and <code>b</code>. Then you can find the minimum Levenstein distance over <code>[b,e]</code> looping over every integer in the interval. There are <code>D</code> of them, so the execution time is about:</p> <p><img src="https://i.stack.imgur.com/llvRH.gif" alt="enter image description here"></p> <p>Now since </p> <p><img src="https://i.stack.imgur.com/7VZu0.gif" alt="enter image description here"></p> <p>we have an algorithm wich is</p> <p><img src="https://i.stack.imgur.com/qSXb1.gif" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload