Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new binary tree node with value 10.
DSA Rust
let root = Box::new(TreeNode { val: [1], left: None, right: None });Attempts:
3 left
💡 Hint
Common Mistakes
Using None instead of an integer value.
Using Some(10) which is incorrect for val field.
✗ Incorrect
The value of the node should be 10, so val: 10 is correct.
2fill in blank
mediumComplete the code to create a left child node with value 5 for the root.
DSA Rust
root.left = Some(Box::new(TreeNode { val: [1], left: None, right: None }));Attempts:
3 left
💡 Hint
Common Mistakes
Using None or Some(5) instead of just 5.
Confusing the left field with val.
✗ Incorrect
The left child node value should be 5, so val: 5 is correct.
3fill in blank
hardFix the error in the code to create a right child node with value 15.
DSA Rust
root.right = Some([1](TreeNode { val: 15, left: None, right: None }));
Attempts:
3 left
💡 Hint
Common Mistakes
Using Some without Box::new causes type mismatch.
Using None means no child node.
✗ Incorrect
The right child must be wrapped in Box::new to allocate on heap.
4fill in blank
hardFill both blanks to create a root node with left and right children 7 and 20.
DSA Rust
let root = Box::new(TreeNode { val: 10, left: Some(Box::new(TreeNode { val: [1], left: None, right: None })), right: Some(Box::new(TreeNode { val: [2], left: None, right: None })) });Attempts:
3 left
💡 Hint
Common Mistakes
Swapping left and right child values.
Using values not specified in the instruction.
✗ Incorrect
Left child value is 7 and right child value is 20 as per the instruction.
5fill in blank
hardFill all three blanks to create a binary tree with root 8, left child 3, and right child 10.
DSA Rust
let root = Box::new(TreeNode { val: [1], left: Some(Box::new(TreeNode { val: [2], left: None, right: None })), right: Some(Box::new(TreeNode { val: [3], left: None, right: None })) });Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of values.
Using values not matching the instruction.
✗ Incorrect
Root value is 8, left child is 3, right child is 10 as required.
