B]DATA STRUCTURE IN C
TREES
please help to device an algorithm to compute the size of the sub-tree rooted at each node .
B]DATA STRUCTURE IN C
TREES
please help to device an algorithm to compute the size of the sub-tree rooted at each node .
Let me see your attempt first.
my attemp is
algorithm subtree_size(tree)
if(tree = empty) then
return 0;
else
return 1 +(subtree_size(leftsubtree) +subtree_size(rightsubtree) )
end
B]DATA STRUCTURE IN C
TREES
please help to device an algorithm to compute the size of the sub-tree rooted at each node .
100
What else do you want? It is fairly good. But what you'll get includes the root. So subtract by 1, you'll get the size of the subtree.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.