def build_random_tree(size):
 root = TreeNode(0)
 for i in range(1, size):
  cursor = root
  while True:
   choice = random.choice(['L', 'R'])
   if (choice == 'L'):
    if cursor.left:
     cursor = cursor.left
    else:
     cursor.left = TreeNode(i)
     break
   elif (choice == 'R'):
    if cursor.right:
     cursor = cursor.right
    else:
     cursor.right = TreeNode(i)
     break
 return root

def build_random_tree ( size ) : root = TreeNode ( 0 ) for i in range ( 1 , size ) : cursor = root while True : choice = random . choice ( [ 'L' , 'R' ] ) if ( choice == 'L' ) : if cursor . left : cursor = cursor . left else : cursor . left = TreeNode ( i ) break elif ( choice == 'R' ) : if cursor . right : cursor = cursor . right else : cursor . right = TreeNode ( i ) break return root
create a randomly constructred tree that is fairly balanced .