Skip to content

错题整理

约 327 个字 1 行代码 预计阅读时间 1 分钟

第五周 单选题 2-5

Among the following binary trees, which one can possibly be the decision tree (the external nodes are excluded) for binary search?

正确答案:A

解析:在二分搜索中,每次求中间值时向下取整还是向上取整是唯一确定的。对应地,向下取整会导致剩下的小于中间值的值少于大于中间值的值,从而使得决策树上的中间值节点的左子树在大小上小于右子树;向上取整则反之。因此本题就是需要判断哪个树的每一个节点都满足左子树小于右子树,或反之。


期中考 单选题 2-8

Suppose that the level-order traversal sequence of a max-heap is { 82, 65, 17, 26, 8, 12, 3 }. Use the linear algorithm to adjust this max-heap into a min-heap, and then call DeleteMin. The preorder traversal sequence of the resulting tree is:

8, 26, 82, 65, 12, 17

8, 17, 12, 26, 65, 82

26, 65, 17, 82, 12, 8

8, 17, 26, 65, 12, 82

正确答案:D

解析:线性时间建堆指的是,对于任何一个完全二叉树,从最后一个非叶子节点开始向下调整。


期中考 程序填空题 5-2

T->Left = BuildTree( );

正确答案:in + 0, pre + 1, i

解析:从中间访问数组应当用指针的加减法运算实现。