ninetynine-1.3.0: Ninety-Nine Haskell Problems
CopyrightCopyright (C) 2021 Yoo Chung
LicenseGPL-3.0-or-later
Maintainerdev@chungyc.org
Safe HaskellSafe-Inferred
LanguageGHC2021

Problems.P56

Description

Part of Ninety-Nine Haskell Problems. Some solutions are in Solutions.P56.

Synopsis

Documentation

symmetric :: Tree a -> Bool Source #

Let us call a binary tree symmetric if you can draw a vertical line through the root node and then the right subtree is the mirror image of the left subtree. Write a function symmetric to check whether a given binary tree is symmetric. We are only interested in the structure, not in the contents of the nodes.

Examples

>>> symmetric (Branch 'x' (Branch 'x' Empty Empty) Empty)
False
>>> symmetric (Branch 'x' (Branch 'x' Empty Empty) (Branch 'x' Empty Empty))
True

Hint

Expand

Write a function mirror first to check whether one tree is the mirror image of another.