avltree/AVLTree.py
def _insert(self, root, key, value) -> AVLNode:
        """Inserts the (key, value) pair in the AVL Tree and 
        self balances itself.

        Args:
            root (AVLNode): the root of the tree
            key (str): the key to be inserted
            value (str): the value to be mapped for key

        Returns:
            AVLNode: resulting root after self balancing itself
        """
        if not root:
            return AVLNode(key, value)

        rkey = root.get_key()

        if key == rkey:
            root.value = value
        elif key < rkey:
            root.left = self._insert(root.left, key, value)
        else:
            root.right = self._insert(root.right, key, value)

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

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

        return root
Inserts the (key, value) pair in the AVL Tree and 
        self balances itself.

        Args:
            root (AVLNode): the root of the tree
            key (str): the key to be inserted
            value (str): the value to be mapped for key

        Returns:
            AVLNode: resulting root after self balancing itself
        
Inserts the (key, value) pair in the AVL Tree and
self balances itself.
Inserts the ( key value ) pair in the AVL Tree and self balances itself .
def _insert(self, root, key, value) -> AVLNode:
        if not root:
            return AVLNode(key, value)
        rkey = root.get_key()
        if key == rkey:
            root.value = value
        elif key < rkey:
            root.left = self._insert(root.left, key, value)
        else:
            root.right = self._insert(root.right, key, value)
        root.height = 1 + max(self._height(root.left),
                              self._height(root.right))
        balance = self._balance_factor(root)
        if balance > 1 and key < root.left.get_key():
            root = self._right_rotate(root)
        elif balance < -1 and key > root.right.get_key():
            root = self._left_rotate(root)
        elif balance > 1 and key > root.left.get_key():
            root.left = self._left_rotate(root.left)
            root = self._right_rotate(root)
        elif balance < -1 and key < root.right.get_key():
            root.right = self._right_rotate(root.right)
            root = self._left_rotate(root)
        return root
def _insert ( self , root , key , value ) -> AVLNode : if not root : return AVLNode ( key , value ) rkey = root . get_key ( ) if key == rkey : root . value = value elif key < rkey : root . left = self . _insert ( root . left , key , value ) else : root . right = self . _insert ( root . right , key , value ) root . height = 1 + max ( self . _height ( root . left ) , self . _height ( root . right ) ) balance = self . _balance_factor ( root ) if balance > 1 and key < root . left . get_key ( ) : root = self . _right_rotate ( root ) elif balance < - 1 and key > root . right . get_key ( ) : root = self . _left_rotate ( root ) elif balance > 1 and key > root . left . get_key ( ) : root . left = self . _left_rotate ( root . left ) root = self . _right_rotate ( root ) elif balance < - 1 and key < root . right . get_key ( ) : root . right = self . _right_rotate ( root . right ) root = self . _left_rotate ( root ) return root
Inserts the (key, value) pair in the AVL Tree and
self balances itself.
Inserts the ( key value ) pair in the AVL Tree and self balances itself .
"""Inserts the (key, value) pair in the AVL Tree and 
        self balances itself.

        Args:
            root (AVLNode): the root of the tree
            key (str): the key to be inserted
            value (str): the value to be mapped for key

        Returns:
            AVLNode: resulting root after self balancing itself
        """
resulting root after self balancing itself
resulting root after self balancing itself
AVLNode
self
root
the root of the tree
the root of the tree
key
the key to be inserted
the key to be inserted
value
the value to be mapped for key
the value to be mapped for key