Let T be a proper binary ttree with root r. Consider the following algorithm. 5.
ID: 3705223 • Letter: L
Question
Let T be a proper binary ttree with root r. Consider the following algorithm.
5. Let T be a proper binary tree with root r. Consider the following algorithm Algorithm traverse(r) Input: Root r of a proper binary tree. if r is a leaf then return 0 else ttraverse(left child of r) ?traverse(right child of r) return s+t+1 What does the algorithm do? (A) It computes the height of the tree. (B) It computes the number of nodes in the tree. (C) It computes the number of nodes in the tree plus 1. (D) It computes the number of leaves in the tree. (E) It computes the number of internal nodes in the tree.Explanation / Answer
Correct option:
E) It computes the number of internal nodes in the tree.
Explanation:
As the algorithm returns 0 for each leaf node then it certainly does not count the number of nodes as well as the number of leaves. So option D, B and C are incorrect. It does not consider the maximum depth of the root so the height of the tree is not the concern for the algorithm So option A is also incorrect. It considers those node only which are not leaf nodes and count those nodes to return the number. Hence the algorithm computes the number of internal nodes , so the correct option is E.
/*Hope this will help you. Thanks.*/
/*If this helps you, please let me know by giving a positive thumbs up. In case you have any queries, do let me know. I will revert back to you. Thank you!!*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.