I have found an efficient algorithm for verifying if a string $\omega$ is of the form $0^n1^n$, where $n \in \mathbb{N}$.
- Scan across $\omega$. If a 1 appears before a 0, then reject.
Repeat so long as some 0s and some 1s remain on the tape.
- Scan across $\omega$. If the total number of 0s and 1s remaining is odd, reject.
- Scan across $\omega$. Cross out every other 0 starting with the first 0.
- Scan across $\omega$. Cross out every other 1 starting with the first 1.
If no 0s and 1s remain in $\omega$, accept. Otherwise, reject.
I generally see how this algorithm is efficient. It gets rid of half of all 1s and 0s every iteration. How does it work though? Why must we reject if the total number of 0s and 1s remaining in $\omega$ is odd?