int total(struct node* root){ if(root){ if(!root->left && !root->right) return 1; return (total(root->left)+total(root->right));} } can be done like this too. But I really like your videos Sir.Keep uploading :)
A Gnutella topology looks like a balanced ternary tree with 4 levels of nodes, i.e., peers, as shown in the picture below. Thus, there is 1 root at Level 1, which has 3 children at Level 2, which each have 3 children at Level 3, which in turn each have 3 children at Level 4 - thus, there are a total of 40 nodes. If the root node (Level 1) sends a Query message with TTL=2, then what are the number of nodes receiving the Query message, not including the originating node? Enter your answer as a numeric value in the text box below.
can you assist me with this method void IncrementLeaves( int value ) - Function: adds value to all the leaves’ info. - Precondition: Tree has been initialized. - Postcondition: Function value = leaves’ info is increased by value.
Global parameter is a bad idea, since you leak information out of the method. We could parametrise count (root, count) and initialise as count (root_of_tree, 0).
int ans=0; int count(struct Node *root) { if(root==NULL) return 0; if(root->left) count(root->left); if(root->right) count(root->right); if(root->left && root->right) ans++; } Is this fine @vivekanand sir.
You explain things very well!!Congrats!!!
Can you please tell me how to make a procedure that prints a particular node???
You just made my day. Thank you!
int total(struct node* root){
if(root){
if(!root->left && !root->right)
return 1;
return (total(root->left)+total(root->right));}
}
can be done like this too. But I really like your videos Sir.Keep uploading :)
GeeksforGeeks Boi
gives segsev for testcase having either left or right child due to not checking of null
How easy you described and solved this problem... Awesome man. Many thanks to you..
🤣🤣🤣
A Gnutella topology looks like a balanced ternary tree with 4 levels of nodes, i.e., peers, as shown in the picture below. Thus, there is 1 root at Level 1, which has 3 children at Level 2, which each have 3 children at Level 3, which in turn each have 3 children at Level 4 - thus, there are a total of 40 nodes.
If the root node (Level 1) sends a Query message with TTL=2, then what are the number of nodes receiving the Query message, not including the originating node? Enter your answer as a numeric value in the text box below.
Goat stuff right here
Thanks for this
How to input a general tree, only algorithm need ?
How to print the count sir my count is printing as much my loop is executing .
thank you
Can u solve closest leaf distance from given k in a binary tree
Thankx sir😄
can you assist me with this method
void IncrementLeaves( int value )
- Function: adds value to all the leaves’ info.
- Precondition: Tree has been initialized.
- Postcondition: Function value = leaves’ info is increased by value.
Great !!
Keep it up!!
Sir please post a video which Print Nodes having K leaves by iteration method and recursive too
yes sure Divyajyoti......u want a n-ary tree?
+Vivekanand Khyade - Algorithm Every Day
no sir its binary tree but i want to print all nodes having k no of leaf nodes
sir make a video on dbms and os
There is no return statement in your solution ?
it is a void function.
Global parameter is a bad idea, since you leak information out of the method. We could parametrise count (root, count) and initialise as count (root_of_tree, 0).
point
wah
I think it should be in preorder traversal instead of inorder @5.49
#Vivekananda sir apne email dedo kuch queries puchne k liye....
int ans=0;
int count(struct Node *root)
{
if(root==NULL)
return 0;
if(root->left)
count(root->left);
if(root->right)
count(root->right);
if(root->left && root->right)
ans++;
}
Is this fine @vivekanand sir.