Binary Search Trees

本文详细介绍了二叉查找树的概念、性质和相关算法,包括中序遍历的时间复杂度证明,以及查找、最小值、最大值、前驱、后继等操作。同时探讨了二叉搜索树的插入和删除操作,并通过练习题加深理解。
摘要由CSDN通过智能技术生成

Definition

A binary search tree is organized, as the name suggests, in a binary tree. Each node is an object. In addition to a key field and satellite data, left, right, and p fields that point to the nodes corresponding to its left child, its right child, and its parent, respectively. If a child or the parent is missing, the appropriate field contains the value NIL.

Property

let x be a node in a binary search tree. If y is a node in the left subtree of x, then key[y] key[x]. If y is a node in the right subtree of x, then key[x] key[y].
The binary-search-tree property allows us to print out all the keys in a binary search tree in sorted order by inorder tree walk.

Theorem If x is the root of an n-node subtree, then the call INORDER-TREE-WALK(x) takes θ(n) time.

Proof: Let T(n) denote the time taken by INORDER-TREE-WALK when it is called on the root of an n-node subtree.
INORDER-TREE-WALK takes a small, constant amount of time on an empty subtree and so T(0) =c for some positive constant c.
For n > 0, suppose that INORDER-TREE-WALK is called on a node x whose left subtree has k nodes and whose right subtree has n-k-1 nodes. The time to perform INORDER-TREE-WALK(x) is T(n)=T(k)+T(nk1)+d

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值