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 reversed version of the original tree.
Click to reveal answer
beginner
In the mirror operation, what happens to the left and right subtrees of a node?
The left subtree becomes the right subtree, and the right subtree becomes the left subtree after mirroring.
Click to reveal answer
beginner
Show the TypeScript function signature to mirror a binary tree node.
function mirrorTree(root: TreeNode | null): TreeNode | nullClick to reveal answer
beginner
What is the base case in the recursive mirror function for a binary tree?
The base case is when the current node is null, meaning there is no subtree to mirror, so the function returns null.
Click to reveal answer
intermediate
Why is recursion a good approach to mirror a binary tree?
Because each node's left and right subtrees can be mirrored independently, recursion naturally handles this by applying the same operation to smaller parts until the whole tree is mirrored.
Click to reveal answer
What is the first step when mirroring a binary tree node?
✗ Incorrect
Mirroring starts by swapping the left and right children of the current node.
What should the mirror function return when it receives a null node?
✗ Incorrect
When the node is null, the function returns null as there is nothing to mirror.
Which traversal method is naturally used in the mirror function?
✗ Incorrect
Preorder traversal is used because we swap children before recursively mirroring subtrees.
After mirroring, what happens to the original left subtree?
✗ Incorrect
The original left subtree becomes the right subtree after mirroring.
What is the time complexity of mirroring a binary tree with n nodes?
✗ Incorrect
Each node is visited once, so the time complexity is O(n).
Explain how you would mirror a binary tree using recursion.
Think about what happens at each node and how recursion helps.
You got /4 concepts.
Describe the changes in the tree structure after mirroring a binary tree.
Imagine flipping the tree like a mirror image.
You got /3 concepts.