Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to find the left child of a node in a BST.
DSA Rust
let left_child = node[1];Attempts:
3 left
💡 Hint
Common Mistakes
Using .right instead of .left
Trying to access .parent instead of child
✗ Incorrect
In a BST, the left child of a node is accessed using the .left field.
2fill in blank
mediumComplete the code to move to the right child of a node in a BST.
DSA Rust
let right_child = node[1];Attempts:
3 left
💡 Hint
Common Mistakes
Using .left instead of .right
Accessing .value instead of child pointers
✗ Incorrect
The right child of a node in a BST is accessed using the .right field.
3fill in blank
hardFix the error in the code to find the minimum node in a BST subtree.
DSA Rust
while current[1].is_some() { current = current[2].as_ref().unwrap().left.as_ref(); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using .right instead of .left in the loop condition
Accessing .parent instead of child
✗ Incorrect
To find the minimum node, we keep moving left while left child exists.
4fill in blank
hardFill both blanks to correctly find the inorder successor when the node has a right child.
DSA Rust
if node.right.is_some() { let mut successor = node.right.as_ref(); while successor[1].is_some() { successor = successor[2].as_ref().unwrap().left.as_ref(); } return successor.cloned(); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using .left first instead of .right
Not moving left inside the loop
✗ Incorrect
When node has right child, successor is leftmost node in right subtree. So move right first, then keep moving left.
5fill in blank
hardFill all three blanks to correctly find the inorder successor when the node has no right child.
DSA Rust
let mut current = node; let mut parent = current.parent.as_ref(); while parent.is_some() && current[1] == parent[2] { current = parent.unwrap(); parent = parent.unwrap().parent.as_ref(); } return parent[3].cloned();
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing current with parent's left child instead of right child
Not moving up the tree correctly
✗ Incorrect
When no right child, move up until current is left child of parent. Then parent is successor.
