0
0
DSA Goprogramming~10 mins

Tree vs Array vs Linked List When Hierarchy Matters in DSA Go - Interactive Comparison Practice

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

Complete the code to create a node struct for a tree with a value and children.

DSA Go
type Node struct {
    Value int
    Children [][1]
}
Drag options to blanks, or click blank then click option'
A*Node
Bint
Cstring
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using int or string instead of Node for Children slice.
Forgetting to use a slice type for multiple children.
2fill in blank
medium

Complete the code to append a child node to a parent node's Children slice.

DSA Go
parent.Children = append(parent.Children, [1])
Drag options to blanks, or click blank then click option'
Aparent
Bchild
CChildren
DValue
Attempts:
3 left
💡 Hint
Common Mistakes
Appending the parent node to its own children.
Appending the Children slice instead of a node.
3fill in blank
hard

Fix the error in this function that prints all node values in a tree recursively.

DSA Go
func printTree(node *Node) {
    if node == nil {
        return
    }
    fmt.Println(node.Value)
    for _, child := range node.[1] {
        printTree(child)
    }
}
Drag options to blanks, or click blank then click option'
ANodes
BValue
Cparent
DChildren
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong field name for children.
Trying to iterate over a non-slice field.
4fill in blank
hard

Fill both blanks to create a linked list node struct with a value and pointer to next node.

DSA Go
type ListNode struct {
    Value int
    [1] *[2]
}
Drag options to blanks, or click blank then click option'
ANext
BListNode
CChild
DNode
Attempts:
3 left
💡 Hint
Common Mistakes
Using Child instead of Next for linked list.
Using Node instead of ListNode for pointer type.
5fill in blank
hard

Fill all three blanks to create a map from string keys to int values for counting frequencies.

DSA Go
freq := map[[1]][2]{}
for _, word := range words {
    freq[word][3] freq[word] + 1
}
Drag options to blanks, or click blank then click option'
Astring
Bint
C=
Dfloat64
Attempts:
3 left
💡 Hint
Common Mistakes
Using float64 instead of int for counts.
Using wrong operator like += instead of =.