I have a user and group database. There are a lot of groups on the database and each group has a lot of member. For example;
- User1 is member of Group1, Group2, Group3
- User2 is member of Group2
- User3 is member of Group2, Group5
There is a parent-child relationship among the groups. Parent groups are more general groups. For example,
- Group2: Programmers
- Group5: .NET Programmers
On the database, there is no parent-child relationship among the groups. How can create dynamic parent-child relationship? I there any algorithm about these problem?
Thanks for reply.
Iterate through every item, filling table child1Parent2[groups,groups]. At start it is full of trues. For every group check condition: g1 is set and g2 is not set. If it is true, set false to chuld1Parent2[gr1,gr2]. At the end of iteration you have the table wich contains all parent-child info.
As a result you have:
child1Parent2[g1,g2] === (g1 is a child of g2)A piece of advice for future: if you want to find some info, think about how this info will be declared, what structure could it have. You’ll understand much more on the subject.