算法与数据结构--树的有关习题

1.What is the depth of the tree in the Figure ?
在这里插入图片描述
Answer:树的深度=根节点到最远叶子的距离,最远:A-B-E-J-L(M),有四条边,所以树的深度为4.
2.Give the prefix, infix, and postfix expressions corresponding to the tree in the figure.
在这里插入图片描述
Answer:先序遍历:先节点–再左子树–再右子树;
中序遍历:先左子树–再节点–再右子树;
后序遍历:先左子树–再右子树–再节点.
prefix:-**ab+cde;
infix:((ab)(c+d))-e;
postfix:ab*cd+*e-

3.a. Show the result of inserting 3, 1, 4, 6, 9, 2, 5, 7 into an initially empty binary search tree.
b. Show the result of deleting the root.
在这里插入图片描述
Answer:a.二叉查找树以中序遍历的方式遍历,按照中序排列规则插入元素画出图像即可;
b.根节点有两个直接相连的子节点,用右边子树上的最小元素替换该节点即可.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值