Tree Properties & Traversals

Answer & solution
Official answer: 1
1. Method and setup. Use one postorder traversal. When processing a node, both child-subtree sizes are already known; combine them with the current node and count it if the total is four. Store size and count in the recursion result rather than recounting descendants for every possible root.
2. Work through the result and its assumptions. A postorder traversal computes each rooted subtree size as 1+left_size+right_size and increments a counter for size 4. It does constant work per node, Θ(n)=O(n¹log⁰n), so a+10b=1.