Counting Phylogenetic Ancestors
This problem asks:
Given: A positive integer n (3≤n≤10000).
Return: The number of internal nodes of any unrooted binary tree having n leaves.
Required reading
Restate the problem
Given the number of leaves in an unrooted binary tree, return the number of internal nodes.
Solution steps
In reading the Wikipedia page on unrooted binary trees, I read this snippet:
In an unrooted binary tree with n leaves, there will be n − 2 internal nodes…
Is it possible that the answer is simply n-2 for any given n?
I don’t even need to write any code to figure that out. I just download the dataset from Project Rosalind and return n-2 as the answer.
Yes! That works. Here’s a Project Rosalind first. I’ve solved a challenge with no code at all.