0
0
DSA Goprogramming~10 mins

Create a Binary Tree Manually in DSA Go - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
ANode
BTree
CNodePtr
DBinaryNode
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different struct name for left or right child.
Forgetting the pointer (*) before the struct name.
2fill in blank
medium

Complete 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'
A0
B10
Cnil
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Setting value to 0 or nil instead of 10.
Confusing the pointer fields with the value field.
3fill in blank
hard

Fix 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'
A0
B10
Cnil
D5
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.
4fill in blank
hard

Fill 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'
A15
Bnil
C0
Droot
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.
5fill in blank
hard

Fill 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'
A7
Bnil
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 instead of nil for child pointers.
Setting wrong value for the leaf node.