The base case should return 0 when the node is None because no node exists there.
Step 2: Identify incorrect return value
Returning 1 for None causes overcounting nodes, leading to wrong total count.
Final Answer:
Base case returns 1 instead of 0 for None -> Option A
Quick Check:
Base case must return 0 for empty node [OK]
Hint: Base case for None must return 0 nodes [OK]
Common Mistakes:
Returning 1 for None
Confusing '==' and 'is' but both work
Missing colon is syntax error
5. Given a binary tree where each node has either 0 or 2 children, and the total number of leaf nodes is 7, what is the total number of nodes in the tree?
hard
A. 15
B. 14
C. 13
D. 16
Solution
Step 1: Use property of full binary tree
In a full binary tree, total nodes = 2 * leaf nodes - 1.
Step 2: Calculate total nodes
Total nodes = 2 * 7 - 1 = 14 - 1 = 13.
Step 3: Recheck formula correctness
Actually, total nodes = 2 * leaf nodes - 1 = 13, but the options include 15 which is the total nodes for a perfect binary tree of height 3 (which has 7 leaves and 15 nodes). Since the tree has nodes with either 0 or 2 children (full binary tree), the formula applies and the correct total nodes is 13.
Final Answer:
13 -> Option C
Quick Check:
Total nodes = 2 * leaves - 1 = 13 [OK]
Hint: Full binary tree nodes = 2 * leaves - 1 [OK]
Common Mistakes:
Using total nodes = leaves * 2
Confusing full and complete tree formulas
Ignoring leaf node count
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.