Answered step by step
Verified Expert Solution
Question
1 Approved Answer
b) Trace the following function on the tree shown in Figure (1) above and draw the resulting Tree showing each step (iteration). void func(treeNode node)
b) Trace the following function on the tree shown in Figure (1) above and draw the resulting Tree showing each step (iteration). void func(treeNode node) if (node = NULL) return; elsefunc(node->left);func(node->right); treeNode* temp; temp = node left; node left = node->right; node->right = temp; Question 2 (10 Marks): a) Given the binary tree (BT) shown in Figure (1). Write a function that counts the number of nodes iff (if and only if) they have data equals to the quotient of their two children. The node is not counted if it has either got only one child or no children at all. You can assume that the tree is already filled with data. Nodes 10,20 will be counted, so the output should be equal to 2 . Node 10 has two children 20 and 2 which satisfies the condition, because 20 divided by two is equal to 10. The same applies for the other counted nodes. Nodes 2,1,15,100,300 and 350 are not counted because they do not satisfy the requirements; either because they have got only one child (e.g. node 2 ), no children at all (e.g. node 15) or the data is not the quotient to their children (e.g. node 300). Figure 1. Binary Tree Activate Windo
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started