So I’m making a program where:
I enter a subset $S$ of a group.
I add $S^{-1}$ (all the inverses in $S$) to $S$
I take $ab^{-1}$ with $a,b$ spanning $S$ and if this produces a new element, I add it to $S$.
If no new elements are produced, the algorithm terminates.
If new elements are produced, the process is repeated.
I implemented this into Java and while it works, it is not very efficient.
In general, is there a way to make this more efficient or is this it? (Not a way to make the code run faster but a more concise way to carry this out)