Thank you for your time Fou Lu.
Your explanation makes sense and it is not easy. After 2 days arriving at nothing I started to get desperate and as a reaction I posted here, and even asked the service of professional codes from the website: www.teaminindia.co.uk
(the first it came on google) as I thought this would be a 4 hour job for a pro and I could afford it.
However that day I worked hard, and now I managed to do the routine. It is based in looping with memorizing the number of loops where the is a multiple branching. Now I adapted that to a function and I am very happy.
IF it was a real family tree with multiple children, I think it would got above my limits, as you clearly explained, but my model involved of always having 2 branches (Descendants) from a parent, and these in turn can have 2, so on so forth, where the descendent is either another parent (keep branching = keep looping) or without children (=routine stops).
So the situation was one of the following 4
Branch to 2 Parents : K K
Branch to a Parent and a non-Parent: K S
Branch to a non-parent and a parent: S K (same as above)
Branch to 2 non parents: S S
SS, KS, SK were no problem: SS stops the lineage, SK / KS the lineage continues through K. However KK involved memorizing one of the K, which can keep going through a series of generations. I solved this by an array_push of the branch (K) to be followed once an SS is reached, and proper out during the loop when executed for the next in line. I place an 'end' in the stack loop array which will mean there is no more memory, and the looping stops.
PS: have ever someone tried these services where you hire a coder to make for you a piece of code? What are the recommendations? E.g.