Example: I have 20 persons as object, and every person knows 0-n others. The direction of the link matters! A person A might know B, but B might not know A. It’s a directed graph.
Edit: For simplification, my node objects (in this case Person objects) are able to store arbitrary information. I know this is not the best design but for now that would be fine.
So in the worst case everyone is connected with everyone else, everyone knows everyone else.
This is no real use case but I want to write a test for this to learn and play around. In a productive environment the number of objects would be limited to about 20, but the ways in which those objects are connected to eachother are unlimited.
This illustrates the problem in a simplified way:
thanks to source
Given a specific person as starting point, I want to walk through the whole graph and examine every possible path exactly once without getting stuck in an infinite loop.
Let’s imagine person A knows B, who knows C, and who knows A. The output might be:
A knows B knows C knows A (ok but we don’t want to end in an infinite loop so we stop here)
A knows C knows A
A knows T knows R knows V
This would be stupid and must be eliminated:
A knows B knows C knows A knows C knows A knows T knows R knows V …
I do have a couple of crazy ideas how to tackle this problem. But…
Question) Must I do that with an Iterative deepening depth-first search (IDDFS)?
Jon was so kind to point out DFS on Wikipedia
I’m stuck with this part in the article:

a depth-first search starting at A,
assuming that the left edges in the
shown graph are chosen before right
edges, and assuming the search
remembers previously-visited nodes and
will not repeat them (since this is a
small graph), will visit the nodes in
the following order: A, B, D, F, E, C,
G. The edges traversed in this search
form a Trémaux tree, a structure with
important applications in graph
theory.
specifically this note:
“(since this is a small graph)”
OK so what if this is a huge graph?
Your data structure is indeed a graph.
I hate to provide such a bare answer, but the question is so basic that Graph Traversal on Wikipedia is more than adequate. The two basic approaches are explained and there is also pseudocode.