Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to compare the target value with the current node's value.
DSA Rust
if target [1] node.value { return true; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '>' instead of '==' causes wrong comparisons.
Using '!=' will check for inequality, which is incorrect here.
✗ Incorrect
We check if the target is equal to the current node's value to find the element.
2fill in blank
mediumComplete the code to decide to search in the left subtree when target is less than current node's value.
DSA Rust
if target [1] node.value { return search(&node.left, target); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' will search the wrong subtree.
Using '==' or '!=' here is incorrect for subtree direction.
✗ Incorrect
If the target is less than the current node's value, we search the left subtree.
3fill in blank
hardFix the error in the recursive call to search the right subtree when target is greater than current node's value.
DSA Rust
if target [1] node.value { return search(&node.right, target); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' will search the wrong subtree.
Using '==' or '!=' here is incorrect for subtree direction.
✗ Incorrect
If the target is greater than the current node's value, we search the right subtree.
4fill in blank
hardFill both blanks to complete the recursive BST search function signature and base case check.
DSA Rust
fn search(node: &Option<Box<Node>>, target: i32) -> bool {
if node.is_[1]() { return [2]; }
let node = node.as_ref().unwrap();Attempts:
3 left
💡 Hint
Common Mistakes
Using 'is_empty()' which is not a method on Option.
Returning true when node is None causes wrong results.
✗ Incorrect
We check if the node is None (empty), then return false because target is not found.
5fill in blank
hardFill all three blanks to complete the recursive BST search function body.
DSA Rust
fn search(node: &Option<Box<Node>>, target: i32) -> bool {
if node.is_[1]() { return [2]; }
let node = node.as_ref().unwrap();
if target [3] node.value { return true; }
else if target < node.value { return search(&node.left, target); }
else { return search(&node.right, target); }
}Attempts:
3 left
💡 Hint
Common Mistakes
Returning true when node is None.
Using wrong comparison operator instead of '=='.
✗ Incorrect
We check if node is None, return false; if target equals node value, return true.
