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

how will you represent hierarchy using graphs?
you need not explicitely represent sibling relationship.. if n nodes are children of a single parent, it obviously means they(those n nodes) are siblings. you need not join them. so i think n-ary is enough to represent family hierarchy
@anusha  no , u have to show the relationship of  sibiling. otherwise they ask to show parent -children relationship , not family hierarchy ( only give one relaxation that u need not show married to relationship....)
so will u keep an edge from grand children to grand parents also?
it depends who implement it . if someone consider to show sibiling or others kind of relationship , then there might chance of getting cycle which  impossible to implement with tree. thats why graph is best option here
edited
but there will be lots of overhead to maintain a graph. morover its a "hierarchy"..  when a simple tree can do, why to go for graph
hmm.. lets see @arjun sir please confirm.

Yes, sometimes questions are bit GK as well.

https://fr.pinterest.com/stobiephyllis/family-tree-templates/

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