let us formalize this definition of the tree data structure by providing some functions that make it easy for us to use lists as trees note that we are not going to define binary tree class the functions we will write will just help us manipulate standard list as though we are working with tree def binary_tree( )return [ [][]the binary_tree function simply constructs list with root node and two empty sublists for the children to add left subtree to the root of treewe need to insert new list into the second position of the root list we must be careful if the list already has something in the second positionwe need to keep track of it and push it down the tree as the left child of the list we are adding the code below shows the python code for inserting left child def insert_left(rootnew_branch) root pop( if len( root insert( [new_brancht[]]elseroot insert( [new_branch[][]]return root notice that to insert left childwe first obtain the (possibly emptylist that corresponds to the current left child we then add the new left childinstalling the old left child as the left child of the new one this allows us to splice new node into the tree at any position the code for insert_right is similar to insert_left and is shown below def insert_right(rootnew_branch) root pop( if len( root insert( [new_branch[] ]elseroot insert( [new_branch[][]]return root to round out this set of tree-making functions let' write couple of access functions for getting and setting the root valueas well as getting the left or right subtrees def get_root_val(root)return root[ def set_root_val(root,new_val)root[ new_val def get_left_child(root)return root[ trees and tree algorithms