0
0
DSA Goprogramming~5 mins

Mirror a Binary Tree in DSA Go - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AThey are duplicated
BThey are swapped
CThey remain the same
DThey are deleted
What is the base case in the recursive mirror function for a binary tree?
ANode is a leaf
BNode has no children
CNode is nil
DNode has two children
Which traversal order is used when mirroring a binary tree recursively?
APre-order (root, left, right)
BLevel-order
CIn-order (left, root, right)
DPost-order (left, right, root)
What is the time complexity of mirroring a binary tree with n nodes?
AO(n)
BO(log n)
CO(n^2)
DO(1)
In Go, what type should the left and right children of a binary tree node be?
A*TreeNode
Bint
Cstring
Dbool
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.