1 Vineet Mishra Prince Asked: October 11, 2019In: Computer Science Sir/Ma’am, help me in solving the question. Q) Algorithm that accepts a Binary Tree as input and prints the number of leaf nodes to standard output. 1 1 Answer Voted Oldest Recent admin Added an answer on October 12, 2019 at 7:00 am Algorithm to count number of leaf in a Binary Tree struct node* NewNode(int data) { struct node* node = new(struct node); // "new" is like "malloc" node->data = data; node->left = NULL; node->right = NULL; return(node); } getLeafCount(struct node* node) { if(node == NULL) return 0; if(node->left == NULL && node->right==NULL) return 1; else return getLeafCount(node->left )+ getLeafCount(node->right); } 0 Reply Share Share data =">Share on Facebook data =&url=https%3A%2F%2Fignouanswers.com%2Fquestion%2Fsir-maam-help-me-in-solving-the-question-q-algorithm-that-accepts-a-binary-tree-as-input-and-prints-the-number-of-leaf-nodes-to-standard-output-2%2F%23comment-86">Share on Twitter data =">Share on LinkedIn data = - https%3A%2F%2Fignouanswers.com%2Fquestion%2Fsir-maam-help-me-in-solving-the-question-q-algorithm-that-accepts-a-binary-tree-as-input-and-prints-the-number-of-leaf-nodes-to-standard-output-2%2F%23comment-86">Share on WhatsApp Leave an answerLeave an answerCancel reply Featured image Select file Browse Save my name, email, and website in this browser for the next time I comment.

Algorithm to count number of leaf in a Binary Tree

struct node* NewNode(int data) {

struct node* node = new(struct node); // "new" is like "malloc"

node->data = data;

node->left = NULL;

node->right = NULL;

return(node);

}

`getLeafCount(struct node* node)`

{

if(node == NULL)

return 0;

if(node->left == NULL && node->right==NULL)

return 1;

else

return getLeafCount(node->left )+ getLeafCount(node->right);

}