FDS作业记录 · 二叉树

1、

It is always possible to represent a tree by a one-dimensional integer array.

T()

F()

乍一看感觉不行,其实是可以的,以下是GPT给出的一个例子:

2、

There exists a binary tree with 2016 nodes in total, and with 16 nodes having only one child.

T()

F()

我们记度(degree)为x的结点个数为n_x,则有:

n_1 = 16, n_0 + n_2 = 2000

其中度为1的结点贡献1条边,度为2的结点贡献2条边,度为0的结点不贡献边。

2016个结点共2015条边,所以有:

16 * 1 + n_2 * 2 = 2015,得n_2= 999.5,故不存在这样的二叉树。

3、

If a general tree T is converted into a binary tree BT, then which of the following BT traversals gives the same sequence as that of the post-order traversal of T?

A.Pre-order traversal

B.In-order traversal

C.Post-order traversal

D.Level-order traversal

将一般树变为二叉树的方法即左子树指向一个child,右子树指向sibling。

这道题我们可以自己画个图试试看:

对于这个general tree(鼠绘,不要在意),它的postorder traversal是

E F B C G H D A

它的preorder traversal是

A B E F C D G H

化为二叉树之后是这样:

美观起见旋转45°:

对于这个二叉树,它的preorder traversal是

A B E F C D G H

它的inorder traversal是

E F B C G H D A

它的postorder traversal是

F E H G D C B A

故选B

PS:这里有个结论最好直接记住,将general tree变为binary tree,

新树的中序遍历为原树的后序遍历;

新树的先序遍历为原树的先序遍历。

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值