0
0
DSA Goprogramming~10 mins

Tree Traversal Postorder Left Right Root 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 call the postorder traversal function recursively on the left child.

DSA Go
func postorder(node *Node) {
    if node == nil {
        return
    }
    postorder(node.[1])
    // Continue traversal
}
Drag options to blanks, or click blank then click option'
ALeft
BRight
CParent
DRoot
Attempts:
3 left
💡 Hint
Common Mistakes
Calling the function on the right child first.
Calling the function on the node itself again.
Using incorrect field names.
2fill in blank
medium

Complete the code to call the postorder traversal function recursively on the right child.

DSA Go
func postorder(node *Node) {
    if node == nil {
        return
    }
    postorder(node.Left)
    postorder(node.[1])
    // Continue traversal
}
Drag options to blanks, or click blank then click option'
ARight
BRoot
CLeft
DParent
Attempts:
3 left
💡 Hint
Common Mistakes
Calling the function on the left child again.
Calling the function on the node itself instead of a child.
Using incorrect field names.
3fill in blank
hard

Fix the error in the code to print the node's value after visiting its children.

DSA Go
func postorder(node *Node) {
    if node == nil {
        return
    }
    postorder(node.Left)
    postorder(node.Right)
    fmt.Println(node.[1])
}
Drag options to blanks, or click blank then click option'
ALeft
BRight
CValue
DParent
Attempts:
3 left
💡 Hint
Common Mistakes
Printing the left or right child instead of the node's value.
Printing the parent pointer which may not exist.
Forgetting to print anything.
4fill in blank
hard

Fill both blanks to complete the postorder traversal function that returns a slice of node values.

DSA Go
func postorderValues(node *Node) []int {
    if node == nil {
        return []int{}
    }
    left := postorderValues(node.[1])
    right := postorderValues(node.[2])
    return append(append(left, right...), node.Value)
}
Drag options to blanks, or click blank then click option'
ALeft
BRight
CParent
DRoot
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping left and right children.
Using non-existent fields like Parent or Root.
Appending values in wrong order.
5fill in blank
hard

Fill all three blanks to build a map of node values to their depths during postorder traversal.

DSA Go
func postorderDepthMap(node *Node, depth int, m map[int]int) {
    if node == nil {
        return
    }
    postorderDepthMap(node.[1], depth+1, m)
    postorderDepthMap(node.[2], depth+1, m)
    m[[3]] = depth
}
Drag options to blanks, or click blank then click option'
ALeft
BRight
Cnode.Value
Ddepth
Attempts:
3 left
💡 Hint
Common Mistakes
Using depth as map key instead of node value.
Swapping left and right children.
Not increasing depth during recursion.