0
0
DSA Goprogramming~10 mins

Morris Traversal Inorder Without Stack 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 move to the left child in Morris Traversal.

DSA Go
current = root
for current != nil {
    if current.Left == nil {
        fmt.Println(current.Val)
        current = current[1]
    } else {
        // Find the inorder predecessor
    }
}
Drag options to blanks, or click blank then click option'
A.Parent
B.Left
C.Right
D.Next
Attempts:
3 left
💡 Hint
Common Mistakes
Moving to .Left instead of .Right causes infinite loop.
Using .Parent or .Next which are not standard pointers in this context.
2fill in blank
medium

Complete the code to find the inorder predecessor in Morris Traversal.

DSA Go
predecessor := current.Left
for predecessor.Right != nil && predecessor.Right != current {
    predecessor = predecessor[1]
}
Drag options to blanks, or click blank then click option'
A.Right
B.Next
C.Parent
D.Left
Attempts:
3 left
💡 Hint
Common Mistakes
Moving left instead of right causes incorrect predecessor.
Using .Parent or .Next which are not relevant here.
3fill in blank
hard

Fix the error in setting the thread link in Morris Traversal.

DSA Go
if predecessor.Right == nil {
    predecessor.Right = current
    current = current[1]
}
Drag options to blanks, or click blank then click option'
A.Next
B.Right
C.Parent
D.Left
Attempts:
3 left
💡 Hint
Common Mistakes
Moving right causes infinite loop.
Using .Parent or .Next which are invalid pointers.
4fill in blank
hard

Fill both blanks to remove the thread and move to the right child in Morris Traversal.

DSA Go
else {
    predecessor.Right = [1]
    fmt.Println(current.Val)
    current = current[2]
}
Drag options to blanks, or click blank then click option'
Anil
B.Left
C.Right
Dcurrent
Attempts:
3 left
💡 Hint
Common Mistakes
Setting predecessor.Right to current causes infinite loop.
Moving left instead of right after removing thread.
5fill in blank
hard

Fill all three blanks to complete the Morris Traversal inorder function.

DSA Go
func morrisInorder(root *Node) {
    current := root
    for current != nil {
        if current.Left == nil {
            fmt.Println(current.Val)
            current = current[1]
        } else {
            predecessor := current.Left
            for predecessor.Right != nil && predecessor.Right != current {
                predecessor = predecessor[2]
            }
            if predecessor.Right == nil {
                predecessor.Right = current
                current = current[3]
            } else {
                predecessor.Right = nil
                fmt.Println(current.Val)
                current = current.Right
            }
        }
    }
}
Drag options to blanks, or click blank then click option'
A.Right
B.Left
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing left and right pointers causes incorrect traversal.
Not removing thread properly leads to infinite loops.