educative.io

Educative

Error with sample code

For Deletion in a BST, the below code section is wrong. The elif conditional block for the right child node deletion has been repeated. The second block should be for deleting the left child.

   # deleting node with right child
    elif self.leftChild is None:
        tmp = self.rightChild
        self = None
        return tmp
    # deleting node with right child
    elif self.leftChild is None:
        tmp = self.rightChild
        self = None
        return tmp

Fixed Code:

    # deleting node with right child
    elif self.leftChild is None:
        tmp = self.rightChild
        self = None
        return tmp
    # deleting node with left child
    elif self.rightChild is None:
        tmp = self.leftChild
        self = None
        return tmp