## Assignment: unrooted trees

We often don’t root phylogenetic trees. This reduces the number of possible trees and is described by the equation:

Text: (2n-5)!/[2n-3*(n-3)!]

Rendered:

$$\frac{(2*n-5)!}{2^{n-3} * (n-3)!}$$

### Assignment part 1

Modify the function used in the “number of phylogenetic trees” tutorial to work for unrooted trees.

You can use the simplest form of the function which doesn’t have any additional argument, eg

The function is here; make the necessary changeas

#code below work for an un-rooted tree
tree_count <- function(n = 3){
numerator   <- factorial(2*n-5)
denominator <- 2^(n-3)*factorial(n-3)
trees  <- numerator / denominator
print(trees)

}
tree_count(n=20)
##  2.216431e+20

## Assignment part 2

Create a function that will work for rooted OR unrooted trees. Do this by adding an additional argument like

type = “rooted”

if(type == "rooted){ #do this }

if(type == "unrooted){ #do something else }

Again, you can use the simplest form of the argument.

tree_count_choice <- function(n, type){

if (type=="unrooted"){
numerator   <- factorial(2*n-5)
denominator <- 2^(n-3)*factorial(n-3)
trees  <- numerator / denominator
}

if (type=="rooted"){
numerator   <- factorial(2*n-3)
denominator <- 2^(n-2)*factorial(n-2)
trees  <- numerator / denominator
}
print(trees)
}
tree_count_choice(n=11,"rooted")
##  654729075
tree_count_choice(n=11,"unrooted")
##  34459425

For this assignment, render to RRubps, submit the link, and submit a screen grab that contains

• the code for the function
• the function returning the value for a rooted tree with 11 taxa
• the function returning the value for an unrooted tree with 11 taxa.