avltree/AVLTree.py
def _delete(self, root, key) -> AVLNode:
        """deletes a key from the tree

        Args:
            root (AVLNode): the root of the tree
            key (str): the key to be deleted

        Returns:
            AVLNode: modifed root of the tree
        """
        if not root:
            return root
        rkey = root.get_key()
        if key < rkey:
            root.left = self._delete(root.left, key)
        elif key > rkey:
            root.right = self._delete(root.right, key)
        else:
            if root.left is None:
                temp = root.right
                root = None
                return temp
            elif root.right is None:
                temp = root.left
                root = None
                return temp
            temp = self._get_min_value_node(root.right)
            root.key = temp.key
            root.value = temp.value
            root.right = self._delete(root.right, temp.key)

        if root is None:
            return root

        root.height = 1 + max(self._height(root.left),
                              self._height(root.right))
        balance = self._balance_factor(root)

        if balance > 1 and self._balance_factor(root.left) >= 0:
            root = self._right_rotate(root)
        elif balance < -1 and self._balance_factor(root.right) <= 0:
            root = self._left_rotate(root)
        elif balance > 1 and self._balance_factor(root.left) < 0:
            root.left = self._left_rotate(root.left)
            root = self._right_rotate(root)
        elif balance < -1 and self._balance_factor(root.right) > 0:
            root.right = self._right_rotate(root.right)
            root = self._left_rotate(root)

        return root
deletes a key from the tree

        Args:
            root (AVLNode): the root of the tree
            key (str): the key to be deleted

        Returns:
            AVLNode: modifed root of the tree
        
deletes a key from the tree
deletes a key from the tree
def _delete(self, root, key) -> AVLNode:
        if not root:
            return root
        rkey = root.get_key()
        if key < rkey:
            root.left = self._delete(root.left, key)
        elif key > rkey:
            root.right = self._delete(root.right, key)
        else:
            if root.left is None:
                temp = root.right
                root = None
                return temp
            elif root.right is None:
                temp = root.left
                root = None
                return temp
            temp = self._get_min_value_node(root.right)
            root.key = temp.key
            root.value = temp.value
            root.right = self._delete(root.right, temp.key)
        if root is None:
            return root
        root.height = 1 + max(self._height(root.left),
                              self._height(root.right))
        balance = self._balance_factor(root)
        if balance > 1 and self._balance_factor(root.left) >= 0:
            root = self._right_rotate(root)
        elif balance < -1 and self._balance_factor(root.right) <= 0:
            root = self._left_rotate(root)
        elif balance > 1 and self._balance_factor(root.left) < 0:
            root.left = self._left_rotate(root.left)
            root = self._right_rotate(root)
        elif balance < -1 and self._balance_factor(root.right) > 0:
            root.right = self._right_rotate(root.right)
            root = self._left_rotate(root)
        return root
def _delete ( self , root , key ) -> AVLNode : if not root : return root rkey = root . get_key ( ) if key < rkey : root . left = self . _delete ( root . left , key ) elif key > rkey : root . right = self . _delete ( root . right , key ) else : if root . left is None : temp = root . right root = None return temp elif root . right is None : temp = root . left root = None return temp temp = self . _get_min_value_node ( root . right ) root . key = temp . key root . value = temp . value root . right = self . _delete ( root . right , temp . key ) if root is None : return root root . height = 1 + max ( self . _height ( root . left ) , self . _height ( root . right ) ) balance = self . _balance_factor ( root ) if balance > 1 and self . _balance_factor ( root . left ) >= 0 : root = self . _right_rotate ( root ) elif balance < - 1 and self . _balance_factor ( root . right ) <= 0 : root = self . _left_rotate ( root ) elif balance > 1 and self . _balance_factor ( root . left ) < 0 : root . left = self . _left_rotate ( root . left ) root = self . _right_rotate ( root ) elif balance < - 1 and self . _balance_factor ( root . right ) > 0 : root . right = self . _right_rotate ( root . right ) root = self . _left_rotate ( root ) return root
deletes a key from the tree
deletes a key from the tree
"""deletes a key from the tree

        Args:
            root (AVLNode): the root of the tree
            key (str): the key to be deleted

        Returns:
            AVLNode: modifed root of the tree
        """
modifed root of the tree
modifed root of the tree
AVLNode
self
root
the root of the tree
the root of the tree
key
the key to be deleted
the key to be deleted