Study Vault Search notes, aliases and full text
Graph
ConceptDBISAI-written · not yet proofread

Prefix Edit Distance

Also PED

The prefix edit distance PED(x, y) is the minimal edit distance between x and any prefix of y, i.e. how many edits the typed query x needs to become a prefix of the word y.

Know these firstEdit Distance

Formula#

Computation. Fill the same DP table MM as for ED, with M[i][j]=ED(x[1..i],y[1..j])M[i][j] = \mathrm{ED}(x[1..i], y[1..j]). The last row holds M[∣x∣][j]=ED(x,y[1..j])M[|x|][j] = \mathrm{ED}(x, y[1..j]), so

PED(x,y)=min⁡0≤j≤∣y∣M[∣x∣][j],\mathrm{PED}(x, y) = \min_{0 \le j \le |y|} M[|x|][j],

the minimum of the last row instead of the bottom-right entry. Time O(∣x∣⋅∣y∣)O(|x| \cdot |y|).

Column cut-off. To decide PED(x,y)≤δ\mathrm{PED}(x, y) \le \delta for a threshold δ\delta, only the first ∣x∣+δ+1|x| + \delta + 1 columns (column ε\varepsilon and y[1..j]y[1..j] for j≤∣x∣+δj \le |x| + \delta) are needed:

PED(x,y)≤δ  ⟹  PED(x,y)=PED(x, y[1..∣x∣+δ]).\mathrm{PED}(x, y) \le \delta \implies \mathrm{PED}(x, y) = \mathrm{PED}\bigl(x,\ y[1..|x|+\delta]\bigr).
ProofProof of the cut-off (exam WS 21/22, Task 3.3)

Let ∣x∣+δ<∣y∣|x| + \delta < |y|. For j>∣x∣+δj > |x| + \delta, property 3 of ED gives ED(x,y[1..j])≥j−∣x∣>δ\mathrm{ED}(x, y[1..j]) \ge j - |x| > \delta. Since PED(x,y)≤δ\mathrm{PED}(x, y) \le \delta, the minimum of the last row is attained at some j≤∣x∣+δj \le |x| + \delta, i.e. at a prefix of y′:=y[1..∣x∣+δ]y' := y[1..|x|+\delta]. The prefixes of y′y' are exactly the prefixes of yy of length ≤∣x∣+δ\le |x| + \delta, so PED(x,y)=PED(x,y′)\mathrm{PED}(x, y) = \mathrm{PED}(x, y').

Properties#

  • PED(x,y)≤ED(x,y)\mathrm{PED}(x, y) \le \mathrm{ED}(x, y), since yy is a prefix of itself.
  • Not symmetric: in general PED(x,y)≠PED(y,x)\mathrm{PED}(x, y) \ne \mathrm{PED}(y, x). E.g. PED(br,breisgau)=0\mathrm{PED}(\text{br}, \text{breisgau}) = 0, but PED(breisgau,br)=ED(breisgau,br)=6\mathrm{PED}(\text{breisgau}, \text{br}) = \mathrm{ED}(\text{breisgau}, \text{br}) = 6 (every prefix of br is at least 6 characters shorter).
  • No length bound: PED(x,y)≥∣ ∣x∣−∣y∣ ∣\mathrm{PED}(x, y) \ge \bigl|\,|x| - |y|\,\bigr| does not hold: PED(br,breisgau)=0\mathrm{PED}(\text{br}, \text{breisgau}) = 0 but ∣ ∣x∣−∣y∣ ∣=6\bigl|\,|x| - |y|\,\bigr| = 6.
  • Padding: left-padding both strings with the same q−1q-1 $ keeps PED unchanged; right-padding does not (see Q-Gram > Padding).
  • PED is the relevance model for fuzzy search-as-you-type: the typed text xx is an incomplete, possibly misspelled prefix of the intended word. Large web search engines all offer this; the entity search on wikidata.org does not.

Example#

  • PED(uni,university)=0\mathrm{PED}(\text{uni}, \text{university}) = 0 (y′=uniy' = \text{uni}), but ED=7\mathrm{ED} = 7.
  • PED(uniwer,university)=1\mathrm{PED}(\text{uniwer}, \text{university}) = 1 (y′=univery' = \text{univer}), but ED=5\mathrm{ED} = 5.
  • PED(fibu,freiburg)\mathrm{PED}(\text{fibu}, \text{freiburg}):
ε\varepsilonfreiburg
ε\varepsilon012345678
f101234567
i211223456
b322232345
u433333234

PED=min⁡(last row)=2\mathrm{PED} = \min(\text{last row}) = 2, attained at y′=freibuy' = \text{freibu}. For the test PED≤2\mathrm{PED} \le 2, only the columns ε\varepsilon, f, r, e, i, b, u (4+2+1=74 + 2 + 1 = 7) are needed; the entries right of the cut are ≥3\ge 3.

Sources#

Search

Type In
↑ ↓ move ↵ open ⇥ next section Ctrl↵ results page Prefix # to search text only