Problem:
Let $V$ be a vector space of dimension $n$ over a field $K$, and let $f, g: V \to V$ be two endomorphisms of $V$ such that $f \circ g = g \circ f$.
(a) If $f$ is diagonalizable and its characteristic polynomial has simple roots, prove that $g$ is also diagonalizable.
(b) If $f^n = 0$ and $f^{n-1} \neq 0$, prove that there exists a polynomial $P \in K[X]$ such that $g = P(f)$.
What I tried:
Suppose such a polynomial $P \in K[x]$ exists. Let's say $$ P(x) = a_{n-1} x^{n-1} + \dots + a_1 x + a_0. $$
I only consider polynomials of degree $n-1$ or less, as every term with $f^n = 0$ vanishes.
Then we consider $f^{n-1} P(f) = f^{n-1} a_{n-1} f^{n-1} + \dots + f^{n-1} a_1 f + f^{n-1} a_0 = f^{n-1} g$. Every term with $f^n$ vanishes. Thus, we obtain $$ a_0 f^{n-1} = f^{n-1} g. $$
As $f$ and $g$ commute, $g(f^{n-1} (v)) = a_0 f^{n-1} (v)$. Therefore, $a_0$ must be an eigenvalue of $g$ as there exists $v \in V$ such that $f^{n-1}(v) \neq 0$ (I have no idea if this is of any use or not).
And after here I'm stuck. I thought about using $v$ and evaluating $P$ at $f^i (v)$ such that some stuff cancels, yet I just get nowhere.
I know that I must use the hypothesis that $f$ and $g$ commute, however I'm not really finding the way to use it.
I also thought about considering a basis $B$ such that $J = [f]_B$ is a Jordan block. Using that, we can say that any matrix that commutes with $J$ is a polynomial in $J$; however, this is just another phrasing of the problem.
Any help is appreciated!
(I edited to add my solution attempts)