Do level order traversal to find deepest node ( temp ) and node to be deleted ( key_node )
while ( len ( q ) ) : NEW_LINE INDENT temp = q . pop ( 0 ) NEW_LINE if temp . data == key : NEW_LINE INDENT key_node = temp NEW_LINE DEDENT if temp . left : NEW_LINE INDENT q . append ( temp . left ) NEW_LINE DEDENT if temp . right : NEW_LINE INDENT q . append ( temp . right ) NEW_LINE DEDENT DEDENT if key_node : NEW_LINE INDENT x = temp . data NEW_LINE deleteDeepest ( root , temp ) NEW_LINE key_node . data = x NEW_LINE DEDENT return root NEW_LINE