Rosalind第35题:Error Correction in Reads

Problem

binary tree is a tree in which each node has degree equal to at most 3. The binary tree will be our main tool in the construction of phylogenies.

rooted tree is a tree in which one node (the root) is set aside to serve as the pinnacle of the tree. A standard graph theory exercise is to verify that for any two nodes of a tree, exactly one path connects the nodes. In a rooted tree, every node  will therefore have a single parent, or the unique node  such that the path from  to the root contains . Any other node  adjacent to  is called a child of  because  must be the parent of ; note that a node may have multiple children. In other words, a rooted tree possesses an ordered hierarchy from the root down to its leaves, and as a result, we may often view a rooted tree with undirected edges as a directed graph in which each edge is oriented from parent to child. We should already be familiar with this idea; it's how the Rosalind problem tree works!

Even though a binary tree can include nodes having degree 2, an unrooted binary tree is defined more specifically: all internal nodes have degree 3. In turn, a rooted binary tree is such that only the root has degree 2 (all other internal nodes have degree 3).

Given: A positive integer  ().

Return: The number of internal nodes of any unrooted binary tree having  leaves.

一个二叉树是树,其中每个节点都有程度至多等于3的二叉树将是我们在系统发育的建设主要工具。

一棵根的树是一棵树,其中一个节点(root)被预留为树的顶峰。一种标准的图形理论练习是验证对于树的任何两个节点,只有一条路径连接了这些节点。在一个根树中,每个节点将因此具有单个或唯一的节点,使得所述路径从到根目录中包含。任何其他节点相邻,以被称为孩子的,因为必须是父 ; 请注意,一个节点可能有多个子节点。换句话说,一棵有根的树具有从根到的有序层次结构,因此,我们经常可以将具有无向边的有根树视为有向图 ,其中每个边从父级到子级定向。我们应该已经熟悉这个想法。这就是Rosalind问题树的工作方式!

即使二叉树可以包含具有等级2的节点,也更明确地定义了无根的二叉树:所有内部节点的等级均为3。反过来,有根的二叉树的结构 是只有根的等级为2(所有其他内部节点的根数均为2)。学位3)。

给定:正整数()。

返回值:任何具有叶的无根二叉树的内部节点数。

 

Sample Dataset

4

Sample Output

2
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值