check if a given binary Tree is a SumTree or not

preview_player
Показать описание
Given a binary tree , check if it is a sumTree or not.
Рекомендации по теме
Комментарии
Автор

This is an unoptimized way. You can make it optimized with this hint: Subtree sum = 2X(currentNode.value) where currentNode is the root of subtree. eg. left subtree sum for tree rooted at 13 is 2*5 = 10 (5+3+2) This is only true for sumtree so this will be the condition.

shobhanksharma
Автор

SIR PLZ GIVE A LECTURE ON ALL THE PROPERTIES OF BINARY TREE AND ALL TYPES OF BINARY TREES IN DETAIL

ghanshamsingh
Автор

Code in python..


def is_sum_tree(self, root):
if root is None:
return False
if root.rchild is None and root.lchild is None:
return root.data
if root.data == self.is_sum_tree(root.lchild) + self.is_sum_tree(root.rchild) :
return True
return False

pymondo
Автор

If it's a leaf node, then I think it should not return 1, it should return (root->val). Tell me if I am wrong

adarshanand
Автор

Here is one more solution(xD): Do the post order traversal of the binary tree and store the data of the node in an array. Then, find the sum of the elements of array till n-2(where n is the size of array). Check if sum is equal to the (n-1)th element of the array, if its is equal then it is a sum tree else not.

manakupadhyay
Автор

Sir,
Please do videos on DATA STRUCTURES and ALGORITHMS on every topic.
Please please....

santhosh........
Автор

sir could you give the a video on find the largest binary search tree in a binary tree program

veerrajuyeleti
Автор

This algo won't work in case of just single node in a tree.

yunususmani
Автор

this solution has o(n^2) time complexity and in interviews we are supposed to give solution in linear time complexity ...so i think this solution is not worthy...please guide me if i am wrong it will be appreciated :)

gauravshukla
Автор

best in india for competitive programming

Vishal-ncju
Автор

Please give the link of the add function video

suvamroy
Автор

what about teaching how to actually create sum-trees?

tjutoxr
Автор

Why does he check if(sumtree(root->left && sumtree(root->right))?
I don't understand

madhusudanaraokaranam
Автор

i'm a little bit confused coze that's not a binary tree ! is it ?

nabilchoukri
visit shbcf.ru