In the above example, once we get to the second 3
node, how do we know we've got a cycle? We need some reference that we've previously encountered this vertex before.
What if we used a nested loop for tracking purposes? Let's take a look at what would happen in pseudocode:
xxxxxxxxxx
iterate through 1 -> 3 -> 5 -> 3 -> 7
iterate through what we've seen so far
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment