On what kind of condition of a compact set $K$ in the plane, $C(K)$ has a generator? Let $K\subset \Bbb{C}$ be a compact subset of the complex plane, and let $C(K)$ be the space of all complex continuous functions on $K$.
We say that $f\in C(K)$ is a generator of $C(K)$ when the set $\{p(f) \mid p\ \style{font-family:inherit;}{\text{is a polynomial}}\}$ is dense in $C(K)$.
If $K$ is any set consisting of finite points, it is easy to check that $C(K)$ has a generator.
If $K=[0,1]$, then we know that $f(x)=x$ is a generator of $C[0,1]$ by Stone-Weierstrass theorem. It follows that $C(\gamma)$ has a generator whenever $\gamma$ is a not a closed simple curve.
Now if $K=S^1$, the unit circle on the plane, then it has been proved that $C(K)$ does not have a generator. It follows that $C(\gamma)$ does not have a generator for any $\gamma$ that is a simple connected curve.
If $K=\overline{\mathbb{D}}$, the unit disk, then by using invariance of domain, a similar method as in the case $K=S^1$ can be given to prove that $C(\overline{\Bbb{D}})$ does NOT have a generator. Similarly, It can be proved that $C(K)$ does NOT have a generator if $K$ has an interior point in $\Bbb{C}$.
How to solve this problem if $K$ does not have an interior point?
 A: A partial answer: if $K$ has empty interior and ${\mathbb C}\setminus K$ is connceted then Lavrentiev's theorem tells us that $P(K)=C(K)$. (See e.g. Gamelin's book on uniform algebras.) In such cases the function $z\mapsto z$ is a generator of $C(K)$ in the sense of your question.
In view of Nik Weaver's observation in the comments I am inclined to guess that this sufficient condition on K is also necessary but I currently don't have time to think about this further.
Note, in view of glenlair's answer and the comment on MSE, that there are obvious examples of such $K$ which are not homeomorphic to subsets of the real line. For instance, take three copies of $[0,1]$ glued together at $\{1\}$ in a tripod shape. This is a compact connected space with the property that removing a certain point leaves three connected components. But compact connected subsets of the real line are closed intervals (or singleton sets) and in those cases removing a point can leave at most two connected components.
A: I believe Yemon's conjecture is correct: $C(K)$ has a generator in the sense of the question if and only if $K$ has empty interior and $\mathbb{C}\setminus K$ is connected. As he points out, the reverse direction follows from Lavrentiev's theorem. For the forward direction, if $K$ has nonempty interior then Mr. Li has already pointed out that we know $C(K)$ has no generator: this easily follows from David Ullrich's answer to a previous question which says that $C(S^1)$ has no generator, and the fact that $K$ contains a homeomorphic copy of $S^1$.
Now suppose $\mathbb{C}\setminus K$ is disconnected and assume $C(K)$ has a generator $f$. I claim that $K$ has a component $K_0$ such that $\mathbb{C}\setminus K_0$ is disconnected. Granting the claim, $C(K_0)$ also has a generator $f$, namely the restriction to $K_0$ of any generator of $C(K)$. It is obvious that $f$ must be 1-1 on $K_0$, so by a standard fact it is a homeomorphism between $K_0$ and $f(K_0)$. According to the answer to this question, $\mathbb{C}\setminus f(K_0)$ is also disconnected. Then $f(K_0)$ contains the boundary of a bounded open set, namely any bounded component of its complement. But now David Ullrich's argument for $S^1$ carries over verbatim to this setting to yield a contradiction. End of proof, modulo the claim.
To verify the claim, let $U$ be a bounded component of $\mathbb{C}\setminus K$, let $V$ be the unbounded component of $\mathbb{C}\setminus\overline{U}$, and let $K_0 = \partial V$.
A: One can get a purely topological characterisation of such compacta by combining two facts.  Firstly, $C(K)$ is singly generated if and only if $K$ is homeomorphic to a subset of the reals.  Secondly, subsets of the reals, even without compactness, have been characterised topologically by several  authors (see, for example, M.E. Rudin, P.J.M. 7 (1957), 1185-1186).
