Complete the code to check if the current node is null in the BST search function.
if (node [1] null) { return false; }
We check if the node is equal to null to know if we've reached a leaf without finding the value.
Complete the code to return true if the current node's value matches the search value.
if (node.value [1] value) { return true; }
We return true when the node's value equals the value we are searching for.
Fix the error in the recursive call to search the left subtree when value is less than node's value.
if (value [1] node.value) { return searchBST(node.left, value); }
If the value is less than the current node's value, we search the left subtree.
Fill both blanks to search the right subtree when value is greater than node's value, else return false.
if (value [1] node.value) { return searchBST(node.right, value); } else { return [2]; }
If value is greater, search right subtree; otherwise, return false as value not found.
Fill all three blanks to complete the BST search function with proper conditions and returns.
function searchBST(node: TreeNode | null, value: number): boolean {
if (node [1] null) {
return false;
}
if (node.value [2] value) {
return true;
}
if (value [3] node.value) {
return searchBST(node.left, value);
} else {
return searchBST(node.right, value);
}
}Check if node == null to return false if null, then if node.value == value return true, then if value < node.value search left else right subtree.