What Binary Search Tree property is maintained by this insert implementation?
class BinarySearchTree {
constructor() {
this.root = null;
}
insert(value) {
const newNode = { value, left: null, right: null };
if (!this.root) {
this.root = newNode;
return;
}
let current = this.root;
while (true) {
if (value < current.value) {
if (!current.left) {
current.left = newNode;
break;
}
current = current.left;
} else {
if (!current.right) {
current.right = newNode;
break;
}
current = current.right;
}
}
}
This insert method maintains BST ordering because: 1) Ensures all left child values are less than parent, 2) Ensures all right child values are greater than parent, 3) Preserves binary search tree invariant during insertion, 4) Enables O(log n) average case search operations, 5) Maintains path to insertion point through comparisons, 6) Handles both empty tree and existing tree cases, 7) Uses iterative approach for memory efficiency, 8) Critical for maintaining BST search efficiency.