数据结构与算法分析-C语言描述--第四章题目答案

部分自己证明 部分翻自该书答案

1-3 不作详细证明

4.4 证明在N个节点的二叉树中,存在N+1个NULL指针代表N+1个儿子。

证: 对于N个节点的二叉树 共有2N个指针 而每个节点(除去根节点)都会占用一个指针,所以有N-1个指针不为空

    所以共有: 2N-(N-1) = N+1 个NULL指针

4.5 证明在高度为H的二叉树中,节点最大个数是2^{H+1}-1

证: 对于高度为H的二叉树,其最大为满二叉树,对于满二叉树,在高度为0的节点数目为2^{H}, 高度为H的点为根节点  节点数目为1,所以节点总数为2^{0}+2^{1}+... + 2^{H} = 2^{H+1}-1

4.6 满节点(full Node)是具有两个儿子的节点。证明满节点的个数加1等于非空二叉树的树叶个数

证: 已知N个节点,满节点个数为x,树叶节点为y,  半节点(只有一个孩子的节点)为z, 可得 x+y+z = N 

由指针数可得   2x+z=N-1   可得 x+1 = y  得证。

4.7 设二叉树有树叶L1,L2,... ,LM,各树叶的深度分别是d1,d2,...,dM。 证明,\sum_{1}^{M}2^{-d_{i}}\leq 1 并确定何时等号成立。

证:

This can be shown by induction. In a tree with no nodes, the sum is zero, and in a one-node tree, the root is a leaf at depth zero, so the claim is true. Suppose the theorem is true for all trees with at most kO nodes. Consider any tree with kO+1 nodes. Such a tree consists of an iO node left subtree and a kO − iO node right subtree. By the inductive hypothesis, the sum for the left subtree leaves is at most one with respect to the left tree root. Because all leaves are one deeper with respect to the original tree than with respect to the subtree, the sum is at most ⁄ 1 2 with respect to the root. Similar logic implies that the sum for leaves in the right subtree is at most ⁄ 1 2, proving the theorem. The equality is true if and only if there are no nodes with one child. If there is a node with one child, the equality cannot be true because adding the second child would increase the sum to higher than 1. If no nodes have one child, then we can find and remove two sibling leaves, creating a new tree. It is easy to see that this new tree has the same sum as the old. Applying this step repeatedly, we arrive at a single node, whose sum is 1. Thus the original tree had sum 1.(先放书中答案)

to be continue...

©️2020 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值