# Counting Rooted Binary Trees solved by 277

July 2, 2012, midnight by Rosalind Team

Topics: Combinatorics, Phylogeny

## From Unrooted to Rooted Trees

Recall that a rooted binary tree is a binary tree for which the root is the only node of degree 2. Such a tree differs from an unrooted binary tree only in the existence of the root.

Different phylogenetic methods may be better suited to rooted or unrooted trees. If a method produces an unrooted tree, then the root (i.e., the common ancestor of all taxa) could theoretically be placed anywhere. Thus, there will be more rooted binary trees than unrooted binary trees on the same number of taxa. The question is: how many more rooted trees are there?

## Problem

As in the case of unrooted trees, say that we have a fixed collection of $n$ taxa labeling the leaves of a rooted binary tree $T$. You may like to verify that (by extension of “Counting Phylogenetic Ancestors”) such a tree will contain $n-1$ internal nodes and $2n-2$ total edges. Any edge will still encode a split of taxa; however, the two splits corresponding to the edges incident to the root of $T$ will be equal. We still consider two trees to be equivalent if they have the same splits (which requires that they must also share the same duplicated split to be equal).

Let $B(n)$ represent the total number of distinct rooted binary trees on $n$ labeled taxa.

Given: A positive integer $n$ ($n \leq 1000$).

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

## Sample Dataset

4


## Sample Output

15
{"ft_lang_label":"__label__en","ft_lang_prob":0.9201356,"math_prob":0.97822154,"size":798,"snap":"2022-27-2022-33","text_gpt3_token_len":200,"char_repetition_ratio":0.1813602,"word_repetition_ratio":0.0,"special_character_ratio":0.21679197,"punctuation_ratio":0.12804878,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97308445,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-06-26T11:45:51Z\",\"WARC-Record-ID\":\"<urn:uuid:633809d1-53be-4da7-8d44-0aee54531918>\",\"Content-Length\":\"16256\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:bda3c1cd-46cb-49ab-bc46-59aefbebb797>\",\"WARC-Concurrent-To\":\"<urn:uuid:9a5100e4-24ae-490a-afbc-8fc4e329e955>\",\"WARC-IP-Address\":\"13.94.194.131\",\"WARC-Target-URI\":\"https://rosalind.info/problems/root/\",\"WARC-Payload-Digest\":\"sha1:GXNRL4NFFTEO6HC7IU2SAMIENJ67ISGL\",\"WARC-Block-Digest\":\"sha1:ILJ3JNZ2QOIJ6KNMCRB6OM5OMSMZYRUN\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-27/CC-MAIN-2022-27_segments_1656103205617.12_warc_CC-MAIN-20220626101442-20220626131442-00275.warc.gz\"}"}