Tree
来源:互联网 发布:金蝶软件 编辑:程序博客网 时间:2024/06/14 01:47
A property of a binary tree is important is that the depth of an average binary tree is considerably smaller than N. Actually, the average depth is O(n√) . And for the the binary search tree, the average value of the depth is O(logN)
4.2.2 An Example: Expression Trees
4.3 The Search Tree ADT–Binary Search Trees
4.3.4 remove
The hardest operation is deletion.
1. If the node is a leaf, it can be deleted immediately.
2. If the node has one child, the node can be deleted after its parent adjusts a link to bypass the node.
3. If the node has two children, the general strategy is to replace the data of this node with the smallest of the right subtree. If the number of deletions is expected to be small, then a popular strategy to use is lazy deletion. This is especially popular if duplicate items are present, because then the filed that keeps count of the frequency of appearance can be decremented. Also, if a deleted item is inserted, the overhead of allocating a new cell is avoided.
4.3.5 Average-Case Analysis
The average depth over all nodes in a tree is
The sum of the depths of all nodes in a tree is known as the internal path length.
For binary search trees,
4.4 AVL Trees
An AVL (Adelson-Velskii and Landis) tree is a binary tree with a balance condition. The balance condition must be easy to maintain, and it ensures that the depth of the tree is
4.5 Splay Trees
A splay tree, that guarantees that any M consecutive tree operations starting from an empty tree take at most O(MlogN) time.
The basic idea of the splay tree is that after a node is accessed, it is pushed to the root by a series of AVL tree rotations.
operation
Let X be a node on the access path at which we are rotating.
1. If the parent of X is the root of the tree, we merely rotate X and the root.
This is the last rotation along the access path.
2. If X has both a parent(P) and a grandparent(G), and there are two cases, plus symmetries. to consider. The first case is the zig-zag, we perform a double rotation, exactly like an AVL double rotation.
3. Otherwise, we have a zig-zag case:X and P are both left children or right children.
The difference is that after an access of the node with item 1, which takes N-1 units, the access on the node with item 2 will only take about
4.6 Tree Traversals
4.7 B-Trees
A B-tree of order M is an M-ary tree with the following properties.
1. The data items are stored at leaves.
2. The nonleaf store up to M - 1 keys to guide the searching; key i represents the smallest key in subtree i+1.
3. The root is either a leaf or has between two and M children.
4. All nonleaf nodes(except the root) has between
5. All leaves are at the same depth and had between
An operation of insertion causes a split into two leaves an then a split of the parent node.
An operation of deletion
Since the leaf has only two items, and its neighbor is already at it minimum of three, we combine the items into a new leaf of five items. As a result, the parent has only two children. However, ti can adopt form a neighbor because the neighbor has four children. As a result, both have three children.
4.8 Sets and Maps in the Standard Library
Top-down red-black trees are used to implement TreeSet and TreeMap in Java whose contains operations in logarithmic worst-caser time.
- Tree
- tree
- tree
- TREE
- Tree
- Tree
- tree
- tree
- tree
- tree
- tree
- tree
- Tree
- Tree
- tree
- TREE
- tree
- tree
- swift中UIActionSheet的使用
- BigDecimal ROUND_HALF_DOWN与ROUND_HALF_UP的区别
- 关于Linux终端回显问题
- APS 审核总结
- H
- Tree
- 在mysql binlog中查看原生的SQL语句
- 《20171126》
- 集成海康在线监控
- 在visual studio中使用mysql
- 【C++】工作中遇到的难点
- 交易系统开发 交易系统源码 交易软件开发 交易软件源码
- jQuery删除cookie
- Fragment onActivityResult 收不到