Let $(G,\cdot)$ be a finite group and $M \subseteq G$, $M\ne \emptyset$.
Prove that the following algorithm computes the subgroup generated by M : $$S_{0}:=\{{e}\} , H_{0}:=\{{e}\}\\ S_{n+1}:=(S_{n}\cdot M)\setminus H_{n}\\ if\: S_{n+1}=\emptyset \: \:then \: \: \langle M \rangle = H_{n}\\ else \: \: H_{n+1}:= H_{n}\cup S_{n+1}$$
Well, I know how to prove it informally but I wonder if there is some more formal-math-not-words proof or if my proof is sufficiently good. Here it is :
Let's look at the nature of the algorithm, if $M=\{{e}\}\:then\:S_{1}=\emptyset \: so \: \langle M \rangle=H_{0}=\{{e}\} $,
otherwise everytime $S_{1}=M$ and $H_1=\{{e}\}\cup M$. We can interpret the set $H_{n+1}$ as the set that stores the values that are generated by $M$ and the set $S_{n+1}$ as the set that generates only new values. $S_{n+1}=\emptyset$ when $S_n\cdot M \subseteq H_n$ and that happens if new values can't be generated anymore. Therefore the set of the subgroup generated by $M$ is $H_n$.
Cheers!
The informal idea is OK. Some remarks:
You will first need some kind of lemma that we only need a subset to be closed under powers to conclude it is a subgroup (this follows from the fact that all $g$ have finite order as $|G|$ is finite, and some basic group theory).
The algorithm is just a way to compute all the products among the set $M$ and their powers as well, keeping track of only the new elements. By finiteness of the group some $S_n$ will have to be empty, as they are pairwise disjoint for different $n$ (which you can probably show by induction). So the algorithm terminates. It's also clear (by induction) that all $H_n \subseteq \langle M \rangle$ and then you have to come up with an argument why we have equality precisely when $S_{n+1} = \emptyset$.