insertion as mentioned previously insertion is an (log noperation provided that the tree is moderately balanced algorithm insert(value prevalue has passed custom type checks for type postvalue has been placed in the correct location in the tree if root root node(value else insertnode(rootvalue end if end insert algorithm insertnode(currentvalue precurrent is the node to start from postvalue has been placed in the correct location in the tree if value current value if current left current left node(value else insertnode(current leftvalue end if else if current right current right node(value else insertnode(current rightvalue end if end if end insertnode the insertion algorithm is split for good reason the first algorithm (nonrecursivechecks very core base case whether or not the tree is empty if the tree is empty then we simply create our root node and finish in all other cases we invoke the recursive insertn ode algorithm which simply guides us to the first appropriate place in the tree to put value note that at each stage we perform binary chopwe either choose to recurse into the left subtree or the right by comparing the new value with that of the current node for any totally ordered typeno value can simultaneously satisfy the conditions to place it in both subtrees