Recall & Review
beginner
What does it mean to mirror a binary tree?
Mirroring a binary tree means swapping the left and right children of every node in the tree, creating a mirror image of the original tree.
Click to reveal answer
beginner
In Go, how do you define a simple binary tree node struct?
type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode
}
Click to reveal answer
beginner
What is the base case when recursively mirroring a binary tree?
The base case is when the current node is nil (empty), meaning there is no node to mirror, so the function returns immediately.
Click to reveal answer
intermediate
Why do we swap the left and right children after recursively mirroring the subtrees?
We swap after recursion to ensure the subtrees themselves are mirrored first, then the current node's children are swapped to complete the mirror effect.
Click to reveal answer
intermediate
What is the time complexity of mirroring a binary tree?
The time complexity is O(n), where n is the number of nodes, because each node is visited once to swap its children.
Click to reveal answer
What happens to the left and right children of a node when mirroring a binary tree?
✗ Incorrect
Mirroring swaps the left and right children of every node.
What is the base case in the recursive mirror function for a binary tree?
✗ Incorrect
The recursion stops when the node is nil (empty).
Which traversal order is used when mirroring a binary tree recursively?
✗ Incorrect
Mirroring uses post-order traversal to first mirror subtrees before swapping children.
What is the time complexity of mirroring a binary tree with n nodes?
✗ Incorrect
Each node is visited once, so time complexity is O(n).
In Go, what type should the left and right children of a binary tree node be?
✗ Incorrect
Left and right children are pointers to TreeNode structs.
Explain step-by-step how to mirror a binary tree using recursion.
Think about what happens at each node and how recursion helps.
You got /4 concepts.
Write the Go function signature and describe the logic to mirror a binary tree.
Focus on input/output and recursive steps.
You got /4 concepts.