Question

How is the algorithm for family tree in genealogy be done?

For example Parent A has a Children B and C. So, what if Children C produce a Children too in the future. How does it add to the tree by using database?

I've looked on Jit's RGraph tree graph where it populates the tree by using JSON data. I might wanna expand the tree by populating the JSON from a database. But, I couldn't figure out how will the database look like if I add more children to the data. I think it is doable if it was only for JSON. But I can't fully grasp when it comes to dynamic data.

What model/structure is suitable to solve this kind of problem?

No correct solution

OTHER TIPS

It could be as simple as this:

enter image description here

FK1 and FK2 that denote FOREIGN KEYs (FATHER_ID references PERSON_ID and MOTHER_ID also references PERSON_ID). FATHER_ID and/or MOTHER_ID can be left NULL if unknown.

This model is not perfect. For example, it doesn't enforce parents' gender (the father is male and mother female) and it only represents biological parents, but not other kinds of relationships such as adoption (all of which can be done, but with certain complications in the model).

However it's very simple and can be naturally traversed (in recursive fashion), analyzed or exported.


For example Parent A has a Children B and C. So, what if Children C produce a Children too in the future. How does it add to the tree by using database?

A child D of C could be represented like this:

PERSON_ID FATHER_ID MOTHER_ID
A
B         A
C         A
D         C

Or like this if C is a mother:

PERSON_ID FATHER_ID MOTHER_ID
A
B         A
C         A
D                   C

IMO it's an adjacency list model with some extension. For example to have 2 parents you can simply add a special (end) node or you can mark the node with a comment.

Might look at prior post using GEDCOM model

I use Union and Person tables with a common Union_ID key in both. In the Person table, this refers to the parents. In the graph, the Union may have 2 inbound parents and an unlimited number of outbound children.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top