Binary Search Tree
2015-10-09 10:06
260 查看
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Binary Search Tree
Binary Search Tree
1 Definition
A binary search tree is a binary tree, where each node has a restriction that the key in any node is larger than the key in its left-child subtree and smaller than any key in its right-child subtree.2 Search
Obviously, if the search key is samller than the key in node, search the key in the node's left subtree;otherwise, search the key in the node's right subtree.3 Insert
It's similar with the search immplemention. At first, search the insert key, if retrun null, then we replace it with the insert key.4 Delete
To delete a node x by replacing it with its successor.1.If node x is null, delete
2.If node x only has one child, then x = x.left/x.right
3.If node x has two child; t =x, x = min(t.right), and x.left = t.left, x.right = deleteMin(t.right)
deleteMin(Node x) if x.left == null return x.right; x.left = deleteMin(x.left)
5 Analysis
The running times of algorithms on binary search trees depend on the shapes of the trees, which, in turn,depend on the order in which keys are inserted. In the best case, a tree with N nodes could be perfectly balanced, with ~ lgN nodes between the root and each null link. In the worst case there could be N nodes on the search path. The balance in typical trees turns out to be much closer to the best case than the worst case.Author: mlhy
Created: 2015-10-09 五 10:06
Emacs 24.5.1 (Org mode 8.2.10)
相关文章推荐
- IOS 异步GET方法请求
- oracle触发器详解
- 查看sql server系统表信息
- [IOS]edgesForExtendedLayout、automaticallyAdjustsScrollViewInsets
- C# 调用CMD
- tomcat out of memory备忘
- angularjs学习笔记—事件指令
- 简单分享开放平台的设计理念和思路
- whatsapp显示不全联系人怎么办
- 【R markdown】rmysql乱码问题
- WampServer下如何配置多域名
- python 输入三个变量,然后按小到大输出(解析)
- 如何用思维导图软件做进度计划?
- 如何从国内镜像获取android源代码
- Android 自定义控件实现ListView索引
- Leetcode88: Gray Code
- SSO单点登录在互联网电商应用中的解决方案(基于CAS的改造)
- B树、B-树、B+树、B*树
- 微信浏览器取消缓存的方法
- Html 图像