《Thinking In Algorithm》06.Binary search tree(二叉查找树)

The search tree data structure supports many dynamic-set operations, includingSEARCH,MINIMUM,MAXIMUM,PREDECESSOR,SUCCESSOR,INSERT, andDELETE. Thus, we can use a search tree both as a dictionary and
摘要由CSDN通过智能技术生成

The search tree data structure supports many dynamic-set operations, includingSEARCH,MINIMUM,MAXIMUM,PREDECESSOR,SUCCESSOR,INSERT, andDELETE. Thus, we can use a search tree both as a dictionary and as a priority queue.


1.Definition:

a binary search tree (BST), sometimes also called anordered or sorted binary tree, is a node-based binary tree data structure which has the following properties:

  • The left subtree of a node contains only nodes with keys less than the node's key.
  • The right subtree of a node contains only nodes with keys greater than the node's key.
  • The left and right subtree each must also be a binary search tree.
  • There must be no duplicate nodes.
Generally, the information represented by each node is a record rather than a single data element. However, for sequencing purposes, nodes are compared according to their keys rather than any part of their associated records.
The major advantage of binary search trees over other data structures is that the related sorting algorithms and search algorithms such as in-order traversal can be very efficient.

Binary search trees are a fundamental data structure used to construct more abstract data structures such as sets, multisets, and associative arrays.

Binary-search-tree property:
Let x be a node in a binary search tree. If y is a node in the left subtree of x, then y.key < x.key. If y is a node in the right subtree of x, then y.key > x.key.


2. operations


2.1  Traversal(遍历)

遍历分为三种,分别是
  • inorder tree walk,print out all the keys in a binary search tree in sorted order by a simple recursive algorithm.
  • preorder tree walk ,prints the root before the values in either subtree.
  • postorder tree walk ,print the root after the values in its subtrees.
inorder tree walk的伪代码:

遍历即将树的所有结点访问且仅访问一次。按照根节点位置的不同分为前序遍历,中序遍历,后序遍历。

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值