7

I want to know that which data structure suits best for storing the family tree for a person, there are spousal, child and parental relationships. Also i want to know that if one person is has blood relationship with other.

It would be good i some data structure from c++ STL can be found.

Just ideas are required.

Abdul Samad
  • 5,748
  • 17
  • 56
  • 70

2 Answers2

4

A graph would be best suited for this, and I suggest you use Boost.

Note that building a family tree can prove to be tricky, as illustrated by this question.

Otherwise, std doesn't define a graph data structure. And since a graph is obviously best suited for your situation, I suggest you either implement your own version, or use Boost.

Community
  • 1
  • 1
Luchian Grigore
  • 253,575
  • 64
  • 457
  • 625
3

Is it homework?

Even if it's called “Tree”, It's a bad structure : imagine two brother who marry two sisters.

A general graph structure would be the best (a tree being a specific form of a graph). The edge would carry the relationship. Then you can run a path finding algorithm (like good old dijkstra) only on edges which represent blood relationship.

And boost::graph is a very good library.

Tristram Gräbener
  • 9,601
  • 3
  • 34
  • 50