Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare the data field in a binary tree node class.
DSA C#
public class TreeNode { public int [1]; public TreeNode left, right; public TreeNode(int value) { this.value = value; left = right = null; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'data' or 'val' instead of 'value' causes mismatch with constructor.
Using 'node' is incorrect as it is not a value field.
✗ Incorrect
The field storing the node's value is named 'value' as used in the constructor and class.
2fill in blank
mediumComplete the code to initialize the left child pointer in the constructor.
DSA C#
public TreeNode(int value) {
this.value = value;
this.left = [1];
this.right = null;
}Attempts:
3 left
💡 Hint
Common Mistakes
Assigning 'this' causes self-reference errors.
Using 'new TreeNode()' requires parameters and is unnecessary.
✗ Incorrect
The left child pointer is initialized to null to indicate no child initially.
3fill in blank
hardFix the error in the constructor to correctly assign the right child pointer.
DSA C#
public TreeNode(int value) {
this.value = value;
left = null;
right = [1];
}Attempts:
3 left
💡 Hint
Common Mistakes
Assigning 'this' causes circular reference.
Assigning 'value' is incorrect as it's an int, not a node.
✗ Incorrect
The right child pointer should be set to null initially, not to 'this' or other values.
4fill in blank
hardFill both blanks to declare and initialize a binary tree node's value and left child.
DSA C#
public class TreeNode { public int [1]; public TreeNode [2]; public TreeNode(int value) { this.value = value; left = null; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up left and right child names.
Using 'data' instead of 'value' for the integer field.
✗ Incorrect
The value field stores the node's data, and left is the left child pointer.
5fill in blank
hardFill all three blanks to declare a binary tree node with value, left, and right pointers.
DSA C#
public class TreeNode { public int [1]; public TreeNode [2], [3]; public TreeNode(int value) { this.value = value; left = right = null; } }
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'node' instead of 'left' or 'right' for child pointers.
Swapping left and right names.
✗ Incorrect
The node has an integer 'value' and two child pointers 'left' and 'right'.
