elif data self dataif self right is noneself right node(dataelseself right insert(dataelseself data data print the tree def printtree(self)if self leftself left printtree(printself data)if self rightself right printtree(preorder traversal root -left ->right def preordertraversal(selfroot)res [if rootres append(root datares res self preordertraversal(root leftres res self preordertraversal(root rightreturn res root node( root insert( root insert( root insert( root insert( root insert( root insert( print(root preordertraversal(root)when the above code is executedit produces the following result