I want to give an upper bound for the number of operations in the group $\mathbb{Z}/n \mathbb{Z}$ that the algorithm makes.
We can find the multiplicative inverse $g^{-1}$ by applying the extended euclidean algorithm for g and n.
The time complexity of the extended euclidean algorithm is $O(\log{a} \log{b})$ when we apply it for a and b.
So we need in our case $O(\log{n} \log{g})=O(\log^2{n})$ time to compute $g^{-1}$.
After that it remains to compute the product $y \cdot g^{-1} \mod n$.
For this, we need $O(\log{y} \log{g^{-1}})=O(\log{n} \log{n})=O(\log^2{n})$ time.