Showing posts with label binary tree. Show all posts
Showing posts with label binary tree. Show all posts

Find out if Binary Tree is Sum tree or Not

Problem:

Binary Tree is Sum tree or Not. [Problem Link]

Explanation:

Write a function which returns True if the given binary tree is a Sum Tree, else False. A sum tree a is a binary tree where the value of a node is the summation of the subtree at both its left and right. An empty tree is also a sum tree and value of its sum can be considered as 0. A leaf node is also considered as sum tree. For example, following is a sum tree,