5 votes 5 votes int func(Node root) { if(root == NULL) return 0; else if(root->left == NULL && root->right == NULL) return 2; else return(3 + func(root->left) + func(root->right)); } Above code is executed on the following rooted tree. What will be the output? Programming in C depth-first-search algorithms data-structures binary-tree + – dd asked Jan 13, 2017 recategorized Jul 6, 2022 by Lakshman Bhaiya dd 946 views answer comment Share Follow See all 5 Comments See all 5 5 Comments reply saurabh rai commented Jan 13, 2017 reply Follow Share i m getting 32 ? 3 votes 3 votes focus _GATE commented Jan 13, 2017 reply Follow Share is it 42 ?? –1 votes –1 votes Prabhanjan_1 commented Jan 13, 2017 reply Follow Share yes 32 is correct . root = 3 + 7(left) + 22(right) 1 votes 1 votes focus _GATE commented Jan 13, 2017 reply Follow Share yes 32 is correct ! 1 votes 1 votes Hira Thakur commented Oct 2, 2017 reply Follow Share nice question 0 votes 0 votes Please log in or register to add a comment.
Best answer 4 votes 4 votes It is adding 3 for all internal vertices & 2 for leaves. Total internal vertices = 6. Total leaves= 7. Therefore count = 6*3 + 7*2 = 32 Aghori answered Jan 13, 2017 selected Jan 13, 2017 by dd Aghori comment Share Follow See all 2 Comments See all 2 2 Comments reply dd commented Jan 13, 2017 reply Follow Share rohit typo ? 0 votes 0 votes Aghori commented Jan 13, 2017 reply Follow Share Corrected. :) 0 votes 0 votes Please log in or register to add a comment.
5 votes 5 votes 32 [each leaf node return 2] Gate Mission 1 answered Jan 13, 2017 Gate Mission 1 comment Share Follow See all 0 reply Please log in or register to add a comment.