0
0
DSA Goprogramming~10 mins

Binary Tree Node Structure 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 define a binary tree node with an integer value.

DSA Go
type Node struct {
    Value int
    Left  *Node
    Right *[1]
}
Drag options to blanks, or click blank then click option'
ANodePtr
Bint
CTree
DNode
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-pointer type for child nodes causes incorrect tree structure.
Using unrelated types like int or Tree instead of Node.
2fill in blank
medium

Complete the code to create a new node with a given integer value.

DSA Go
func NewNode(val int) *Node {
    return &Node{Value: [1]
}
Drag options to blanks, or click blank then click option'
ANode
Bval
Cval.Value
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using an undefined variable like value or Node instead of val.
Trying to access val.Value which does not exist.
3fill in blank
hard

Fix the error in the code to assign the left child node correctly.

DSA Go
func (n *Node) SetLeft(child *Node) {
    n.Left = [1]
}
Drag options to blanks, or click blank then click option'
A&child
B*child
Cchild
DNode
Attempts:
3 left
💡 Hint
Common Mistakes
Using &child causes type mismatch (pointer to pointer).
Using *child tries to assign a value instead of a pointer.
4fill in blank
hard

Fill both blanks to check if a node is a leaf (no children).

DSA Go
func (n *Node) IsLeaf() bool {
    return n.Left == [1] && n.Right == [2]
}
Drag options to blanks, or click blank then click option'
Anil
Btrue
Cfalse
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using true or false instead of nil for pointer checks.
Using 0 which is not valid for pointers.
5fill in blank
hard

Fill all three blanks to create a map of node values to their left child values if present.

DSA Go
func LeftChildMap(root *Node) map[int]int {
    result := make(map[int]int)
    if root.Left != [1] {
        result[[2]] = root.Left.[3]
    }
    return result
}
Drag options to blanks, or click blank then click option'
Anil
Broot.Value
CValue
Droot.Left
Attempts:
3 left
💡 Hint
Common Mistakes
Using root.Left instead of root.Value as map key.
Using root.Left instead of Value to get child's value.
Checking against true or false instead of nil.