[Answered ]-Recursive function to calculate the children of a parent

1๐Ÿ‘

A very simple solution would be to create a collection containing your starting node when you call compute_children for the first time and before the loop that you have, add all the children to the collection, ignoring any child that has already found its way into the collection.

In graph-theory this kind of approach is usually referred to as coloring, that is, you store what nodes were already visited somehow, so in the future you will not revisit the same nodes if a cycle is present.

๐Ÿ‘คLajos Arpad

Leave a comment