Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to declare a struct for a binary tree node.
DSA Go
type Node struct {
value int
left *[1]
right *Node
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different struct name for left or right child.
Forgetting the pointer (*) before the struct name.
✗ Incorrect
The left child pointer should be of type *Node to refer to the same struct type.
2fill in blank
mediumComplete the code to create a new node with value 10.
DSA Go
root := &Node{value: [1], left: nil, right: nil} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting value to 0 or nil instead of 10.
Confusing the pointer fields with the value field.
✗ Incorrect
The root node should have the value 10 as specified.
3fill in blank
hardFix the error in assigning the left child node with value 5.
DSA Go
root.left = &Node{value: [1], left: nil, right: nil} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the root value 10 instead of 5 for the left child.
Assigning nil or zero instead of the correct value.
✗ Incorrect
The left child node should have the value 5 as specified.
4fill in blank
hardFill both blanks to create the right child node with value 15 and no children.
DSA Go
root.right = &Node{value: [1], left: [2], right: nil} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or root instead of 15 for value.
Using 0 or root instead of nil for left child pointer.
✗ Incorrect
The right child node has value 15 and no left child (nil).
5fill in blank
hardFill all three blanks to create a leaf node with value 7 and no children.
DSA Go
leaf := &Node{value: [1], left: [2], right: [3] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of nil for child pointers.
Setting wrong value for the leaf node.
✗ Incorrect
A leaf node has a value and both left and right pointers are nil.