Diameter is equal to the path between the two farthest nodes leaf1 and leaf2
getDiameterPath ( leaf1 , leaf2 , - 1 , path ) NEW_LINE pathSize = len ( path ) NEW_LINE if ( pathSize % 2 == 1 ) : NEW_LINE INDENT print ( path [ int ( pathSize / 2 ) ] * - 1 ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( path [ int ( pathSize / 2 ) ] , " , ▁ " , path [ int ( ( pathSize - 1 ) / 2 ) ] , sep = " " , end = " " ) NEW_LINE DEDENT