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,
新树的中序遍历为原树的后序遍历;
新树的先序遍历为原树的先序遍历。