Find the bottom of a general tree in Python

Job ID: 34981043

Budget: £20 – £250 GBP

Let me just say that this is not a binary tree problem.

I would like a solution that implements OOP with minimal for-loops.

we need to find the bottom of the tree and combine them into an equation (essentially, we are expanding an equation) - each node has an equation (children) and we want to expand it up to the lowest level.

some of the nodes of the tree have no levels i.e. the node is already equal to the bottom of the tree and in other cases, the roots have quite a lot of levels possibly, my guess is around 20 levels.

the data is already in a dataframe.