0
0
DSA Typescriptprogramming~10 mins

BST Search Operation in DSA Typescript - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if the current node is null in the BST search function.

DSA Typescript
if (node [1] null) {
  return false;
}
Drag options to blanks, or click blank then click option'
A<
B==
C>
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' causes wrong logic.
Using '>' or '<' to compare with null is incorrect.
2fill in blank
medium

Complete the code to return true if the current node's value matches the search value.

DSA Typescript
if (node.value [1] value) {
  return true;
}
Drag options to blanks, or click blank then click option'
A<
B!=
C>
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' causes wrong results.
Using '>' or '<' here is incorrect.
3fill in blank
hard

Fix the error in the recursive call to search the left subtree when value is less than node's value.

DSA Typescript
if (value [1] node.value) {
  return searchBST(node.left, value);
}
Drag options to blanks, or click blank then click option'
A<
B==
C>
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' causes searching the wrong subtree.
Using '==' or '!=' here is incorrect.
4fill in blank
hard

Fill both blanks to search the right subtree when value is greater than node's value, else return false.

DSA Typescript
if (value [1] node.value) {
  return searchBST(node.right, value);
} else {
  return [2];
}
Drag options to blanks, or click blank then click option'
A>
Btrue
Cfalse
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' causes wrong subtree search.
Returning true in else block is incorrect.
5fill in blank
hard

Fill all three blanks to complete the BST search function with proper conditions and returns.

DSA Typescript
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);
  }
}
Drag options to blanks, or click blank then click option'
A==
B!=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '==' for null check causes wrong logic.
Using '!=' to compare node.value and value is incorrect.
Using '>' instead of '<' for subtree decision is wrong.