0
0
DSA Goprogramming~10 mins

Tree Traversal Inorder Left Root Right 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 print the left subtree first in inorder traversal.

DSA Go
func inorder(node *Node) {
    if node == nil {
        return
    }
    inorder(node.[1])
    fmt.Print(node.value, " ")
    inorder(node.right)
}
Drag options to blanks, or click blank then click option'
Aroot
Bright
Cparent
Dleft
Attempts:
3 left
💡 Hint
Common Mistakes
Calling inorder on node.right first.
Calling inorder on node.parent which does not exist.
Skipping the left subtree.
2fill in blank
medium

Complete the code to print the root value in inorder traversal.

DSA Go
func inorder(node *Node) {
    if node == nil {
        return
    }
    inorder(node.left)
    fmt.Print(node.[1], " ")
    inorder(node.right)
}
Drag options to blanks, or click blank then click option'
Aleft
Bvalue
Cright
Dparent
Attempts:
3 left
💡 Hint
Common Mistakes
Printing node.left or node.right instead of node.value.
Printing node.parent which is not part of the node struct.
3fill in blank
hard

Fix the error in the inorder traversal code to correctly traverse the right subtree.

DSA Go
func inorder(node *Node) {
    if node == nil {
        return
    }
    inorder(node.left)
    fmt.Print(node.value, " ")
    inorder(node.[1])
}
Drag options to blanks, or click blank then click option'
Aright
Bleft
Cparent
Droot
Attempts:
3 left
💡 Hint
Common Mistakes
Calling inorder on node.left again instead of node.right.
Calling inorder on node.parent or node.root which do not exist.
4fill in blank
hard

Fill both blanks to complete the inorder traversal function that prints nodes in left-root-right order.

DSA Go
func inorder(node *Node) {
    if node == nil {
        return
    }
    inorder(node.[1])
    fmt.Print(node.[2], " ")
    inorder(node.right)
}
Drag options to blanks, or click blank then click option'
Aleft
Bvalue
Cright
Dparent
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping left and right children.
Printing node.left or node.right instead of node.value.
5fill in blank
hard

Fill all three blanks to complete the inorder traversal function that prints nodes in left-root-right order.

DSA Go
func inorder(node *Node) {
    if node == nil {
        return
    }
    inorder(node.[1])
    fmt.Print(node.[2], " ")
    inorder(node.[3])
}
Drag options to blanks, or click blank then click option'
Aleft
Bvalue
Cright
Dparent
Attempts:
3 left
💡 Hint
Common Mistakes
Using node.parent which does not exist.
Swapping left and right children in recursive calls.