simple python program to get the next largest element in a tree