📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!


    Question

    An insert(root, value) function for a Binary Search Tree

    (BST) is implemented recursively. After inserting several elements, a search(root, value) function correctly finds most values, but fails to find some values that were definitely inserted. Upon inspection, it's found that the insert function sometimes creates a new node but doesn't correctly link it to its parent. Which of the following is a common mistake in a recursive BST insertion that could cause this?
    A Not handling the root is None base case correctly. Correct Answer Incorrect Answer
    B Incorrectly comparing value with root.data (e.g., using > instead of >=). Correct Answer Incorrect Answer
    C Forgetting to return the root (or the new node) from the recursive call, thus not updating the parent's child pointer. Correct Answer Incorrect Answer
    D Attempting to balance the tree during insertion. Correct Answer Incorrect Answer
    E Not checking for duplicate values. Correct Answer Incorrect Answer

    Solution

    The correct answer is C

    Practice Next
    ask-question