LA 4847 binary search tree

A binary search tree is a binary tree. It may be empty. If it is not
empty, it satisfies the following properties: (1) Every node has a
key, and no two nodes have the same key. (2) The keys in a nonempty
left subtree must be smaller than the key in the root of the subtree.
(3) The keys in a nonempty right subtree must be larger than the key
in the root of the subtree. (4) The left and right subtrees are also
binary search trees. Sample binary search trees are shown in Figure 1.
Figure 1. binary search trees To search for a node with a key k in a
binary search tree T , we begin at the root. If T is empty, T contains
no keys and the search is unsuccessful. Otherwise, we compare k with
the key in root. If k equals root’s key, then the search terminates
successfully. If k is less than root’s key, we search the left subtree
of the root. If k is larger than root’s key, we search the right
subtree of the root. In the same way, we can proceed the search in the
left or right subree of T . To insert a new key k into a binary search
tree T where k is different from those of existing keys in T , we
first search the tree T . The search will be unsuccessful, then we
insert the key at the point the search terminated. For instance, to
insert a key 80 into the Figure 1(a), we first search the tree for 80.
This search terminates unsuccessfully, and the last node examined has
key 40. We insert a new node containing 8

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值