  Tandem duplication in DNA is the process of inserting a copy of a segment of
DNA adjacent to the original position. Motivated by applications that store
data in living organisms, Jain {\em et al.} (2016) proposed the study of codes
that correct tandem duplications to improve the reliability of data storage. We
investigate algorithms associated with the study of these codes.
  Two words are said to be ${\le}k$-confusable if there exists two sequences of
tandem duplications of lengths at most $k$ such that the resulting words are
equal. We demonstrate that the problem of deciding whether two words is
${\le}k$-confusable is linear-time solvable through a characterisation that can
be checked efficiently for $k=3$. Combining with previous results, the decision
problem is linear-time solvable for $k\le 3$. We conjecture that this problem
is undecidable for $k>3$.
  Using insights gained from the algorithm, we study the size of
tandem-duplication codes. We improve the previous known upper bound and then
construct codes with larger sizes as compared to the previous constructions. We
determine the sizes of optimal tandem-duplication codes for lengths up to
twenty, develop recursive methods to construct tandem-duplication codes for all
word lengths, and compute explicit lower bounds for the size of optimal
tandem-duplication codes for lengths from 21 to 30.
