Problem
Figure 1. This unrooted binary tree may be represented in Newick format by (((a,b),c),(d,e)); another way of encoding it is ((a,b),(c,(d,e))).
图1 。这个无根的二叉树可以用([[((a,b),c),(d,e))的Newick格式表示; 另一种编码方式是((a,b),(c,(d,e))))。
Recall the definition of Newick format from “Distances in Trees” as a way of encoding trees. See Figure 1 for an example of Newick format applied to an unrooted binary tree whose five leaves are labeled (note that the same tree can have multiple Newick representations).
Given: A collection of species names representing taxa.
Return: A list containing all unrooted binary trees whose leaves are these taxa. Trees should be given in Newick format, with one tree on each line; the order of the trees is unimportant.
回顾“树中的距离”中Newick格式的定义,作为对树进行编码的一种方式。有关 应用于无根二叉树的Newick格式的示例,请参见图1,该树的五叶标记为标记(请注意,同一棵树可以具有多个Newick表示形式)。
给定:代表以下物种名称的集合 分类单元。
返回值:包含所有无根二叉树的列表,这些树的叶子是这些分类单元。树木应以Newick格式给出,每行一棵树;树木的顺序并不重要。
Sample Dataset
dog cat mouse elephant
Sample Output
(((mouse,cat),elephant))dog; (((elephant,mouse),cat))dog; (((elephant,cat),mouse))dog;