Tree is a hierarchical data structure. One instance of tree is Binary tree, in which each node has maximum two child.

Following program implement the complete binary tree with single method call.

class Node:

def __init__(self, data):

self.data = data

self.left = None

self.right = None

class BinaryTree:

def __init__(self):

self.root = None

def create_tree(self):

data = int(input('enter root node'))

if data == -1:

return

new_node = Node(data)

self.root = new_node

self.create_lefttree(new_node)

self.create_righttree(new_node)

def create_lefttree(self,node):

data = int(input('Enter the left child of {0}'.format(node.data)))

if(data == -1):

return

new_node = Node(data)

self.create_lefttree(new_node)

node.left = new_node

self.create_righttree(new_node)

return def create_righttree(self,node):

data = int(input('enter the right child of {0}'.format(node.data)))

if data == -1:

return

new_node = Node(data)

self.create_righttree(new_node)

node.right = new_node

self.create_lefttree(new_node)

returnbinaryTree = BinaryTree() #creating one instance of BinaryTree

binaryTree.create_tree()