#K59182. Symmetric Binary Tree
Symmetric Binary Tree
Symmetric Binary Tree
Given a binary tree, determine whether it is symmetric about its center. In other words, check if the tree is a mirror image of itself. The binary tree is provided in level order, where the token null
represents a missing node. An empty tree is considered symmetric.
Hint: Consider using a recursive approach that compares the left subtree with the right subtree for mirror symmetry.
inputFormat
The first line of input contains an integer n
, representing the number of tokens in the level order traversal of the binary tree. If n > 0
, the next line contains n
space-separated tokens. Each token is either an integer or the string null
(which represents an absent node). A value of n = 0
indicates an empty tree.
outputFormat
Output a single line with either true
or false
(without quotes). Print true
if the binary tree is symmetric (a mirror of itself) and false
otherwise.
7
1 2 2 3 4 4 3
true