I need to model a four generational family tree starting with a couple. After that if I input a name of a person and a relation like 'brother' or 'sister' or 'parent' my code should output the person's brothers or sisters or parents. I have a fair bit of knowledge of python and self taught in DSA. I think I should model the data as a dictionary and code for a tree DS with two root nodes(i.e, the first couple). But I am not sure how to start. I just need to know how to start modelling the family tree and the direction of how to proceed to code. Thank you in advance!
0
votes
1 Answers
5
votes
There's plenty of ways to skin a cat, but I'd suggest to create:
- A
Person
class which holds relevant data about the individual (gender) and direct relationship data (parents, spouse, children). - A dictionary mapping names to
Person
elements.
That should allow you to answer all of the necessary questions, and it's flexible enough to handle all kinds of family trees (including non-tree-shaped ones).