def delete(selfp)"""delete the node at position pand replace it with its childif any return the element that had been stored at position raise valueerror if position is invalid or has two children ""node self validate(pif self num children( = raise valueerrorp has two children might be none child node left if node left else node right if child is not nonechild grandparent becomes parent child parent node parent if node is self rootchild becomes root self root child elseparent node parent if node is parent leftparent left child elseparent right child self size - convention for deprecated node node parent node return node element def attach(selfpt )"""attach trees and as left and right subtrees of external ""node self validate(pif not self is leaf( )raise valueerrorposition must be leaf if not type(selfis type( is type( )all trees must be same type raise typeerrortree types must match self size +len( len( attached as left subtree of node if not is empty) root parent node node left root set instance to empty root none size attached as right subtree of node if not is empty) root parent node node right root set instance to empty root none size code fragment nonpublic update methods for the linkedbinarytree class (continued from code fragment