363 views

What would be an appropraite data structure to represent family hierarchy where each node is an individual and there in no requirement to keep "married to" relationship?

1. Binary Tree
2. n-ary Tree
3. Graph

it's graph??
how it can be tree??

with binary tree is not possible . cause we cannot represent one hving more than two children.

with n tree not possible . we can not represent sibiling or other kind of relationship that creates cycle.

yes, with graph , it is possible. and it is aprropriate.

with cyclic doubly linked list , it is possible to implement but it takes lot of space for double pointers . it is not appropriate than graph .

so i will go with option c

sir if married to is present then tree cant do it i think. in that case we use graphs? bcoz wife belongs to some other family.
yes..
Sir still can’t understand how n-ary tree will be enough to show both siblings and parents relation simultaneously.

In the figures on Pinterest, either it is depicted as single child with all their parents (& no siblings are present), or both mother & father aren’t depicted as a node in tree can have only 1 parent

It is definitely n-ary tree.

Linked List can't represent someone having two children.

Binary tree can't represent someone having three children.

A graph can represent A's child to be the father of B if A and B are siblings. (Visualize it)

An n-ary tree would represent someone having  number of children, without disrupting the hierarchy.

Option B

1
453 views
1 vote
2
3
381 views