function for getting mode of a tree