Checking tree diameter