Here are the tables $\PRED$ for the word $w=\sa{abacbaca}$:
$j$ | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
$x[j]$ | $\sa{a}$ | $\sa{b}$ | $\sa{a}$ | $\sa{c}$ | $\sa{b}$ | $\sa{a}$ | $\sa{c}$ | $\sa{a}$ |
$\PRED_0[j]$ | -1 | -1 | 0 | -1 | 1 | 2 | 3 | 5 |
$\PRED_1[j]$ | -1 | -1 | -1 | -1 | 1 | 2 | -1 | |
$\PRED_2[j]$ | -1 | -1 | -1 | -1 | -1 |
The associated set $\CAND_w$ is $\{(0,4),(1,7),(2,8)\}$. Only the pair $(1,7)$ corresponds to a square, namely $w[1\dd 6]=\sa{bacbac}$.
Problem 66: Word Square-Freeness with DBF |
The dictionary of Basic Factors (DBF} in short) is a useful elementary data structure to produce efficient algorithmic solutions to many problems on words. It is used here to test the square-freeness of a word.
The DBF of a word $w$ consists of a logarithmic number of tables $\NAME_k$, $0\leq k \leq \log|w|$. Tables are indexed by positions on $w$ and $\NAME_k[j]$ intends to identify $w[j\dd j+2^k-1]$, factor of length $2^k$ starting at position $j$ on $w$. Identifiers have the following property, for $i\neq j$: $\NAME_k[i]=\NAME_k[j]$ if and only if $$i+2^k-1,j+2^k-1\lt |w| \mbox{ and } w[i\dd i+2^k-1]=w[j\dd j+2^k-1].$$ It is known that the DBF of $w$ can be computed in time $O(|w|\log |w|)$.
To test the square-freeness of $w$, let $\PRED_k$, $0\leq k\lt \log|w|$, denote the table indexed by positions on $w$ and defined by $$\PRED_k[j] = \max\{i\lt j \mid \NAME_k[i]=\NAME_k[j]\}\cup\{-1\}$$ and let $\CAND_w$ denote the set of pairs of positions $(i,2j-i)$ on $w$, candidates for a square occurrence $w[i\dd 2j-i-1]$ in $w$: $$\CAND_w = \{(i,2j-i) \mid 2j-i\leq |w| \mbox{ and } i=\PRED_k[j]\ne -1 \mbox{ for some } k\}.$$