I need to know how in a tree I can search for the deepest leaf of the tree. If there were two sheets with the same depth it wouldn't matter which one it was on.
It is assumed that I already have the Tree class created, and also the function that creates a tree from a list. I put such a function in the following code. I will also put the function that allows me to know if a node is a leaf or not.
def profundidad (arbol):
profundidad = 0
izdo = 0
dcho = 0
if Es_hoja(arbol):
profundidad = 1
info = arbol.info
return profundidad , info
else:
if not arbol.izdo.esvacio:
izdo,infoi = profundidad(arbol.izdo)
elif not arbol.dcho.esvacio:
dcho,infod = profundidad(arbol.dcho)
if (izdo > dcho):
return izdo+1,infoi
else:
return dcho+1, infod
With this code I try to obtain the depth of the tree and the information it has, however it gives me an error.