Genetic Algorithms and Equations in Free Groups and Semigroups