I have a class that is used to represent a Person object. Within each Person object there are multiple array lists containing, say, friends, family and other Person objects. I'm now trying to figure out what the best way would be to find the total relatives of that person.
For example:
A has B as family... B has X and Y as family... X has Z as family... and so on.
In the above example, A would have 4 family members up until the person Z. Using nested loops seem like a very bad idea here especially if the data is very large. Suggestion of better data structures or efficient ways to tackle this would be great.