Processing math: 100%

Counting Unrooted Binary Trees solved by 438

July 2, 2012, midnight by Rosalind Team

Topics: Combinatorics, Phylogeny

Counting Treesclick to expand

A natural question is to be able to count the total number of distinct unrooted binary trees having n leaves, where each leaf is labeled by some taxon. Before we can count all these trees, however, we need to have a notion of when two such trees are the same.

Our tool will be the split. Recall from “Creating a Character Table” that removing any edge from a tree T separates its leaves into sets S and Sc, so that each edge of T can be labeled by this split SSc. As a result, an unrooted binary tree can be represented uniquely by its collection of splits.

Problem

Two unrooted binary trees T1 and T2 having the same n labeled leaves are considered to be equivalent if there is some assignment of labels to the internal nodes of T1 and T2 so that the adjacency lists of the two trees coincide. As a result, note that T1 and T2 must have the same splits; conversely, if the two trees do not have the same splits, then they are considered distinct.

Let b(n) denote the total number of distinct unrooted binary trees having n labeled leaves.

Given: A positive integer n (n1000).

Return: The value of b(n) modulo 1,000,000.

Sample Dataset

5

Sample Output

15

Please login to solve this problem.

Welcome to Rosalind!

Rosalind is a platform for learning bioinformatics through problem solving.
Please login with Google/Twitter/Facebook or register a new account.