AVL Tree
来源:互联网 发布:长寿 知乎 编辑:程序博客网 时间:2024/05/16 23:34
Based on“Data Structures and Algorithm Analysis Edition 3.2 (C++ Version)” from C. A. Shaffer
Properties
An AVL tree is a type of self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by more than one, rebalancing is done to restore this property.
Lookup, insertion, and deletion all take O(log n) time in both the average and worst cases.
Operations
Rotate
In discrete mathematics, tree rotation is an operation on a binary tree that changes the structure without interfering with the order of the elements. Rotation is the basic operation of AVL Tree. When rotating, the programmer should note that this operation may result in a new root for the entire tree and take care to update pointers accordingly.
Rotation is used for AVL Tree rebalancing. One can strategically apply rotations to nodes whose left child and right child differ in height by more than 1.
Search
AVL Tree searching is just the same as BST searching: if greater, go left; else, go right.
Insert
- The first step to insert is the same as insert a new node into a BST;
- After that, it’s necessary to check each of the node’s ancestors whether it’s balanced. If not, rotation is needed.
Remove
- The first step to remove is the same as remove a node in a BST;
- After that, balance checking is necessary. If not balanced, rotation is needed.
Performance
For search, insert and remove operations, the costs are all O(logn).
- AVL Tree
- AVL- tree
- avl tree
- AVL Tree
- AVL-TREE
- AVL Tree
- AVL Tree
- AVL Tree
- AVL tree
- AVL tree
- AVL Tree implemention
- AVL Tree Rotation
- AVL Tree 学习笔记
- AVL Tree 的实现
- Sicily 3825. AVL Tree
- Root of AVL Tree
- pat 1066(AVL Tree)
- Class Project: AVL Tree
- BestCoder Round #63 (div.2) sequence1
- Linxu笔记(6): yum在线安装与光盘环境搭建
- Linux socket对EINTR处理
- hihocoder #1093
- code[vs]最小生成树 1078,1231
- AVL Tree
- vijos1441 打鼹鼠 (动态规划)
- Android 关闭和开启四大组件的方法
- Serializable中的serialVersionUID到底有啥用
- Java中类加载过程和对象创建过程
- recvmsg 断包问题
- angular的基础知识
- HDU 5567 sequence1(暴力)——BestCoder Round #63(div.2)
- Linxu笔记(7): 用户信息管理