I have been given the following problem and was wondering if my solution is correct (taken from the textbook exercise in the book Introduction to the Theory of Computation by Martin Sipser): Given $$\text{INFINITE}_{\text{PDA}} =\{\langle M\rangle \mid M\text{ is a PDA }\text{and L(M) is infinite}\}$$
Prove that $\text{INFINITE}_{\text{PDA}}$ is decidable.
The following is my solution:
On input <M>:
1. Repeat until there are transitions:
a. Mark current state and delete the transition that moved you to the state
b. If an already marked state is reached, accept
2. If no other transition exists, reject
Can this be considered a valid solution? I think the fact that we are checking if a cycle exists in the PDA is sufficient to prove that the language is infinite am I correct? I believe there could be a PDA that has a loop in a non-accepting branch of the computation and my algorithm would still say it has an infinite language which is wrong, am I correct?