Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'd go for a recursive algorithm with implicit backtracking. Function signature: <code>f: input -&gt; result</code>, with <code>input</code> being the string, <code>result</code> either <code>true</code> or <code>false</code> depending if the entire string can be tokenized correctly.</p> <p>Works like this:</p> <ol> <li>If <code>input</code> is the empty string, return <code>true</code>.</li> <li>Look at the length-one prefix of <code>input</code> (i.e., the first character). If it is in the dictionary, run <code>f</code> on the suffix of <code>input</code>. If that returns <code>true</code>, return <code>true</code> as well.</li> <li>If the length-one prefix from the previous step is not in the dictionary, or the invocation of <code>f</code> in the previous step returned <code>false</code>, make the prefix longer by one and repeat at step 2. If the prefix cannot be made any longer (already at the end of the string), return <code>false</code>.</li> <li>Rinse and repeat.</li> </ol> <p>For dictionaries with low to moderate amount of ambiguous prefixes, this <em>should</em> fetch a pretty good running time in practice (O(n) in the average case, I'd say), though in theory, pathological cases with O(2^n) complexity can probably be constructed. However, I doubt we can do any better since we need backtracking anyways, so the "instinctive" O(n) approach using a conventional pre-computed lexer is out of the question. ...I think.</p> <p><strong>EDIT:</strong> the estimate for the average-case complexity is likely incorrect, see my comment.</p> <p>Space complexity would be only stack space, so O(n) even in the worst-case.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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