Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new binary tree node with value 10.
DSA C#
TreeNode root = new TreeNode([1]);Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around 10 makes it a string, which is incorrect.
Using null will create an empty node, not a node with value.
✗ Incorrect
The TreeNode constructor takes an integer value. So, 10 is correct.
2fill in blank
mediumComplete the code to assign a left child node with value 5 to the root.
DSA C#
root.[1] = new TreeNode(5);
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'right' assigns to the wrong child.
Using 'child' or 'node' are not valid properties.
✗ Incorrect
The left child of a binary tree node is assigned to the 'left' property.
3fill in blank
hardFix the error in the code to assign a right child node with value 15 to the root.
DSA C#
root.[1] = new TreeNode(15);
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Right' with uppercase R causes a compile error.
Using 'leftChild' or 'childRight' are invalid property names.
✗ Incorrect
The correct property name for the right child is 'right' (lowercase).
4fill in blank
hardFill both blanks to create a root node with value 20 and assign a left child with value 10.
DSA C#
TreeNode root = new TreeNode([1]); root.[2] = new TreeNode(10);
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning the child to 'right' instead of 'left'.
Using wrong root value.
✗ Incorrect
The root node value is 20, and the left child is assigned to 'left'.
5fill in blank
hardFill all three blanks to create a root node with value 30, assign left child 20 and right child 40.
DSA C#
TreeNode root = new TreeNode([1]); root.[2] = new TreeNode(20); root.[3] = new TreeNode(40);
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up left and right properties.
Using wrong values for nodes.
✗ Incorrect
Root value is 30, left child assigned to 'left', right child assigned to 'right'.
