All of these are GPL violations if it can be shown you looked at a GPL function while copying this.
On the other hand, if you came up with it on your own and it happened to look similar, then it's fine.
If there is a threshold, then it is possible to rewrite the original code in ways that do not resemble the original code verbatim, but are effectively the same.
That's an interesting question. In general, the answer is no, but could change depending on if you had the function open at the time of writing the new function.
But a lot of us have knowledge of basic data structures, etc, from reading GPL-licensed code (or perhaps even proprietary code in textbooks). So, in general, coming up with your own understanding is fine.
The violation is where you subsequently pass it off as a novel creation.
Being hard to solve doesn't make a problem go away, though. This is a place where I'm somewhat curious where it ends up. Frankly I think the outcome is more interesting for artistic works (e.g. poetry or images) than practical ones like code, since current generations of AI seem so much better at the former. Still interesting either way.