Trees & SearchD1Phase 2treerecursiontransformation

Invert Binary Tree

Mirror a binary tree by swapping each node's left and right children.

Easy Explanation

Invert Binary Tree mirrors a tree by swapping the left and right child at every node.

Visualizer
O(1)Invert Binary Tree
Deterministic tree mirroring playback with per-node visit and child-swap events.

Traversal

n/a

Visited

0

Swaps

0

Result

Inverting

Ready

Press Play or Step to start execution.

Original

empty

Current Frame

empty

Final Output

empty

Tree is empty. Use values or randomize to generate a run.
currentswappedvisited
Invert Binary Tree Implementation
Pseudocode + TypeScript
Reference implementation examples are intentionally abstracted from the playback engine so learners can map concepts to code.
pseudocode
function invertTree(node):
  if node is null:
    return null

  swap node.left and node.right

  invertTree(node.left)
  invertTree(node.right)

  return node
1.00xNo Run