Let $(A, \leq)$ be a totally ordered alphabet.The packing ${\tt pack(u)}$ of a word $u \in A^*$ is the word of $\lbrace 1, \dots, k \rbrace^*$, where $k$ is the number of different letters of $u$, obtained by crushing every letter of $u$.Formally, let $f_u:A\to \lbrace 1, \dots, k \rbrace$ such that $f_u(x)\leq f_u(y) \Leftrightarrow x\leq y$. Then, if $u=u_1 \dots u_n$, ${\tt pack(u)}$ is the sequence $f_u(u_1) \dots f_u(u_n)$. For instance, let $A$ be the alphabet $\lbrace a_i : i \in \mathbb{N} \rbrace$ where $a_i \leq a_j$ if and only if $i \leq j$ and $u := a_6 a_2 a_2 a_5 a_1 a_9 a_1$. Then, we have ${\tt pack(u)} = 4223151$.Questions areWhat is the best algorithm to compute the packing of a word?What is the (time and space) complexity of this problem assuming $\leq$ is computable in constant space and time?
Complexity of the packing
cc.complexity theory;co.combinatorics