Question

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

  • T 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.
B Incorrectly comparing value with root.data (e.g., using > instead of >=).
C Forgetting to return the root (or the new node) from the recursive call, thus not updating the parent's child pointer.
D Attempting to balance the tree during insertion.
E Not checking for duplicate values.
Practice Next

Hey! Ask a query