Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to swap the left and right child nodes of the root.
DSA C#
var temp = root.left;
root.left = root.[1];
root.right = temp;Attempts:
3 left
💡 Hint
Common Mistakes
Swapping with root.left again instead of root.right.
Using incorrect property names like parent or child.
✗ Incorrect
Swapping root.left with root.right mirrors the root's immediate children.
2fill in blank
mediumComplete the code to recursively mirror the left subtree.
DSA C#
if (root.left != null) { [1](root.left); }
Attempts:
3 left
💡 Hint
Common Mistakes
Calling a wrong function like PrintTree or TraverseTree.
Not calling recursively at all.
✗ Incorrect
The function MirrorTree is called recursively on the left child to mirror the subtree.
3fill in blank
hardFix the error in the recursive call to mirror the right subtree.
DSA C#
if (root.right != null) { [1](root.right); }
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect function names like MirrorTrees or MirrorTreeRight.
Misspelling the function name.
✗ Incorrect
The correct function name is MirrorTree to recursively mirror the right subtree.
4fill in blank
hardFill both blanks to complete the mirror function that swaps children and recursively mirrors subtrees.
DSA C#
public void MirrorTree(Node root) {
if (root == null) return;
var temp = root.[1];
root.[2] = root.left;
root.left = temp;
if (root.left != null) MirrorTree(root.left);
if (root.right != null) MirrorTree(root.right);
}Attempts:
3 left
💡 Hint
Common Mistakes
Swapping with wrong properties like parent or child.
Mixing up left and right assignments.
✗ Incorrect
First, store root.right in temp, then assign root.right to root.left, and finally assign temp to root.left to swap children.
5fill in blank
hardFill all three blanks to complete the mirror function that swaps children and recursively mirrors both subtrees.
DSA C#
public void MirrorTree(Node root) {
if (root == null) return;
var temp = root.[1];
root.[2] = root.left;
root.left = temp;
if (root.left != null) [3](root.left);
if (root.right != null) MirrorTree(root.right);
}Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong function names for recursion.
Swapping with wrong child properties.
✗ Incorrect
Swap root.right with root.left, then recursively call MirrorTree on the left child to mirror subtrees.
