Finding largest family in graph

81 views Asked by At

This is a homework for a data structures course. I'm not asking for code, but I have hard time coming up with an effective algorithm for this :l

I have information about different family trees. Among those I have to find out the largest family and return the name of the greatest elder and number of his descendants. The descendants may have kids between them (a brother and a sister may have a kid) and this has to be done in at least O(n^2).

What would be the most effective way to solve this? I imagine having a breadth first search on graphs, but that means I have to keep up children counters for many levels upwards (if I am traversing a grand^99 children for example).

1

There are 1 answers

1
Kevin Winata On BEST ANSWER

CMIIW, but my assumption is every family tree is separated from each other and the root is the eldest ancestor. If that's the case, since you're counting all tree nodes regardless, I think any unweighted graph traversal algorithm would give the same result. BFS would do the job. I don't get what you mean by "keeping up children counters for many levels upwards" though, just 1 counter is fine right?