数据结构与算法分析-AVL树深入探讨

.title { text-align: center; margin-bottom: .2em }
.subtitle { text-align: center; font-size: medium; font-weight: bold; margin-top: 0 }
.todo { font-family: monospace; color: red }
.done { font-family: monospace; color: green }
.priority { font-family: monospace; color: orange }
.tag { background-color: #eee; font-family: monospace; padding: 2px; font-size: 80%; font-weight: normal }
.timestamp { color: #bebebe }
.timestamp-kwd { color: #5f9ea0 }
.org-right { margin-left: auto; margin-right: 0px; text-align: right }
.org-left { margin-left: 0px; margin-right: auto; text-align: left }
.org-center { margin-left: auto; margin-right: auto; text-align: center }
.underline { text-decoration: underline }
#postamble p,#preamble p { font-size: 90%; margin: .2em }
p.verse { margin-left: 3% }
pre { border: 1px solid #ccc; padding: 8pt; font-family: monospace; overflow: auto; margin: 1.2em }
pre.src { position: relative; overflow: visible; padding-top: 1.2em }
pre.src::before { display: none; position: absolute; background-color: white; top: -10px; right: 10px; padding: 3px; border: 1px solid black }
pre.src:hover::before { display: inline }
pre.src-asymptote::before { content: "Asymptote" }
pre.src-awk::before { content: "Awk" }
pre.src-C::before { content: "C" }
pre.src-clojure::before { content: "Clojure" }
pre.src-css::before { content: "CSS" }
pre.src-D::before { content: "D" }
pre.src-ditaa::before { content: "ditaa" }
pre.src-dot::before { content: "Graphviz" }
pre.src-calc::before { content: "Emacs Calc" }
pre.src-emacs-lisp::before { content: "Emacs Lisp" }
pre.src-fortran::before { content: "Fortran" }
pre.src-gnuplot::before { content: "gnuplot" }
pre.src-haskell::before { content: "Haskell" }
pre.src-hledger::before { content: "hledger" }
pre.src-java::before { content: "Java" }
pre.src-js::before { content: "Javascript" }
pre.src-latex::before { content: "LaTeX" }
pre.src-ledger::before { content: "Ledger" }
pre.src-lisp::before { content: "Lisp" }
pre.src-lilypond::before { content: "Lilypond" }
pre.src-lua::before { content: "Lua" }
pre.src-matlab::before { content: "MATLAB" }
pre.src-mscgen::before { content: "Mscgen" }
pre.src-ocaml::before { content: "Objective Caml" }
pre.src-octave::before { content: "Octave" }
pre.src-org::before { content: "Org mode" }
pre.src-oz::before { content: "OZ" }
pre.src-plantuml::before { content: "Plantuml" }
pre.src-processing::before { content: "Processing.js" }
pre.src-python::before { content: "Python" }
pre.src-R::before { content: "R" }
pre.src-ruby::before { content: "Ruby" }
pre.src-sass::before { content: "Sass" }
pre.src-scheme::before { content: "Scheme" }
pre.src-screen::before { content: "Gnu Screen" }
pre.src-sed::before { content: "Sed" }
pre.src-sh::before { content: "shell" }
pre.src-sql::before { content: "SQL" }
pre.src-sqlite::before { content: "SQLite" }
pre.src-forth::before { content: "Forth" }
pre.src-io::before { content: "IO" }
pre.src-J::before { content: "J" }
pre.src-makefile::before { content: "Makefile" }
pre.src-maxima::before { content: "Maxima" }
pre.src-perl::before { content: "Perl" }
pre.src-picolisp::before { content: "Pico Lisp" }
pre.src-scala::before { content: "Scala" }
pre.src-shell::before { content: "Shell Script" }
pre.src-ebnf2ps::before { content: "ebfn2ps" }
pre.src-cpp::before { content: "C++" }
pre.src-abc::before { content: "ABC" }
pre.src-coq::before { content: "Coq" }
pre.src-groovy::before { content: "Groovy" }
pre.src-bash::before { content: "bash" }
pre.src-csh::before { content: "csh" }
pre.src-ash::before { content: "ash" }
pre.src-dash::before { content: "dash" }
pre.src-ksh::before { content: "ksh" }
pre.src-mksh::before { content: "mksh" }
pre.src-posh::before { content: "posh" }
pre.src-ada::before { content: "Ada" }
pre.src-asm::before { content: "Assembler" }
pre.src-caml::before { content: "Caml" }
pre.src-delphi::before { content: "Delphi" }
pre.src-html::before { content: "HTML" }
pre.src-idl::before { content: "IDL" }
pre.src-mercury::before { content: "Mercury" }
pre.src-metapost::before { content: "MetaPost" }
pre.src-modula-2::before { content: "Modula-2" }
pre.src-pascal::before { content: "Pascal" }
pre.src-ps::before { content: "PostScript" }
pre.src-prolog::before { content: "Prolog" }
pre.src-simula::before { content: "Simula" }
pre.src-tcl::before { content: "tcl" }
pre.src-tex::before { content: "TeX" }
pre.src-plain-tex::before { content: "Plain TeX" }
pre.src-verilog::before { content: "Verilog" }
pre.src-vhdl::before { content: "VHDL" }
pre.src-xml::before { content: "XML" }
pre.src-nxml::before { content: "XML" }
pre.src-conf::before { content: "Configuration File" }
table { border-collapse: collapse }
caption.t-above { caption-side: top }
caption.t-bottom { caption-side: bottom }
td,th { vertical-align: top }
th.org-right { text-align: center }
th.org-left { text-align: center }
th.org-center { text-align: center }
td.org-right { text-align: right }
td.org-left { text-align: left }
td.org-center { text-align: center }
dt { font-weight: bold }
.footpara { display: inline }
.footdef { margin-bottom: 1em }
.figure { padding: 1em }
.figure p { text-align: center }
.inlinetask { padding: 10px; border: 2px solid gray; margin: 10px; background: #ffffcc }
#org-div-home-and-up { text-align: right; font-size: 70%; white-space: nowrap }
textarea { }
.linenr { font-size: smaller }
.code-highlighted { background-color: #ffff00 }
.org-info-js_info-navigation { border-style: none }
#org-info-js_console-label { font-size: 10px; font-weight: bold; white-space: nowrap }
.org-info-js_search-highlight { background-color: #ffff00; color: #000000; font-weight: bold }
.org-svg { width: 90% }
pre.src { background-color: #292b2e; color: #b2b2b2 }
pre.src { background-color: #292b2e; color: #b2b2b2 }

数据结构与算法分析-AVL树深入探讨

Table of Contents

  • 1. 数据结构之-AVL树深入探讨

    • 1.1. AVL树介绍
    • 1.2. AVL树的四种不平衡情形

1 数据结构之-AVL树深入探讨

之前学习数据结构与算法分析C语言描述的时候, 学到了AVL树, 陷入了重重的陷阱, 如今把一一踩过的陷阱都描述出来, 好让自己温故知新.

1.1 AVL树介绍

  • AVL(Adelson-Velskii和Landis)树是带有平衡条件的二叉查找树.这个平衡条件必须要容易保持.而且它须保证树的深度是 \(O(\log{N})\).
  • 一棵AVL树是其任意节点的左子树和右子树的高度绝对值最多差1的二叉查找树.
  • 下图是AVL树和非AVL树

1.2 AVL树的四种不平衡情形

  • AVL树的任意节点 a 的两棵子树(左儿子和右儿子)的高度差2就会出现不平衡状态.
  • 不平衡情形分为四种
    • a 的左儿子(L)的左子树(L)进行一次插入. LL情形
    • a 的左儿子(L)的右子树(R)进行一次插入. LR情形
    • a 的右儿子(R)的左子树(L)进行一次插入. RL情形
    • a 的右儿子(R)的右边子树(R)进行一次插入. RR情形

Date: 2018-11-19 22:15

Author: devinkin

Created: 2018-11-19 一 22:16

Validate

原文地址:https://www.cnblogs.com/devinkin/p/9986167.html

时间: 2024-08-04 22:21:50

数据结构与算法分析-AVL树深入探讨的相关文章

数据结构(三)实现AVL树

AVL树的定义 一种自平衡二叉查找树,中面向内存的数据结构. 二叉搜索树T为AVL树的满足条件为: T是空树 T若不是空树,则TL.TR都是AVL树,且|HL-HR| <= 1 (节点的左子树高度与节点的右子树高度差的绝对值小于等于1) 说明 AVL树的实现类为AVLTree继承自前篇中的二叉搜索树BTreeSort ,AVL树的节点类为AVLNode继承自二叉树节点类BTreeNode. 实现代码 AVL树节点定义 1  public class AVLNode extends BTreeNo

数据结构-平衡二叉树(AVL树)

一.平衡二叉树的定义 使树的高度在每次插入元素后仍然能保持O(logn)的级别 AVL仍然是一棵二叉查找树 左右子树的高度之差是平衡因子,且值不超过1 //数据类型 struct node{ int v, height; node *lchild, *rchild; }; //新建一个结点 node* newNode(int v){ node* Node = new node; Node->v = v; Node->height = 1; Node->lchild = Node->

[数据结构与算法] : AVL树

头文件 1 typedef int ElementType; 2 3 #ifndef _AVLTREE_H_ 4 #define _AVLTREE_H_ 5 6 struct AvlNode; 7 typedef struct AvlNode *Position; 8 typedef struct AvlNode *AvlTree; 9 10 AvlTree MakeEmpty(AvlTree T); 11 Position Find(ElementType X, AvlTree T); 12

数据结构与算法分析java——树

1. 基本术语 度(degree):一个节点的子树个数称为该节点的度: 树中结点度的最大值称为该树的度. 层数(level):从根结点开始算,根节点为1 高度(height)/深度(depth):节点的最大层数 2. 二叉树性质 满二叉树: 完全二叉树: 3. 二叉树的存储结构 1)顺序存储结构 2)链式存储 4. 二叉树的遍历 1)前序遍历: 根  左子树 右子树 2)中序遍历 3)后序遍历 4)层次遍历:从上往下,从左到右 5. 数和二叉树的转换及树的存储结构 1)树转化为二叉树 2)二叉树

数据结构与算法分析java——树2(二叉树类型)

1. 二叉查找树 二叉查找树(Binary Search Tree)/  有序二叉树(ordered binary tree)/ 排序二叉树(sorted binary tree) 1). 若任意节点的左子树不空,则左子树上所有结点的值均小于它的根结点的值: 2). 若任意节点的右子树不空,则右子树上所有结点的值均大于它的根结点的值: 3). 任意节点的左.右子树也分别为二叉查找树. 4). 没有键值相等的节点(no duplicate nodes). public class BinarySe

平衡二叉搜索树(AVL树,红黑树)数据结构和区别

平衡二叉搜索树(Balanced Binary Search Tree) 经典常见的自平衡的二叉搜索树(Self-balancing Binary Search Tree)有 ① AVL树 :Windows NT 内核中广泛使用 ② 红黑树:C++ STL(比如 map.set )Java 的 TreeMap.TreeSet.HashMap.HashSet  Linux 的进程调度  Ngix 的 timer 管理 1 AVL树  vs  红黑树 ①AVL树 平衡标准比较严格:每个左右子树的高度

《数据结构与算法分析:C语言描述》复习——第四章“树”——AVL树

2014.06.15 16:22 简介: AVL树是一种高度平衡的二叉搜索树,其命名源自于联合发明算法的三位科学家的名字的首字母.此处“平衡”的定义是:任意节点的左右子树的高度相差不超过1.有了这个平衡的性质,使得AVL树的高度H总是接近log(N),因此各种增删改查的操作的复杂度能够保证在对数级别.没有bad case是AVL树与普通的二叉搜索树的最大区别.为了实现平衡性质,我们需要记录每个节点的高度(或者平衡因子)来检测不平衡的情况.为了修正高度不平衡,需要用到“旋转”的方法,分为单旋转和双

数据结构之AVL树

说明:本文仅供学习交流,转载请标明出处,欢迎转载! 在前面的博文中,我们已经介绍了数据结构之二分查找树的相关知识,二分查找的提出主要是为了提高数据的查找效率.同一个元素集合可以对应不同的二分查找树BST,二分查找树的形态依赖于元素的插入顺序.同时我们也已经知道,如果将一个有序的数据集依次插入到二查找树中,此时二分查找树将退化为线性表,此时查找的时间复杂度为o(n).为了防止这一问题的出现,便有了平衡二叉树的存在价值.平衡二叉树从根本上将是为了防止出现斜二叉树的出现,从而进一步提高元素的查找效率,

图解数据结构树之AVL树

AVL树(平衡二叉树): AVL树本质上是一颗二叉查找树,但是它又具有以下特点:它是一棵空树或它的左右两个子树的高度差的绝对值不超过1,并且左右两个子树都是一棵平衡二叉树.在AVL树中任何节点的两个子树的高度最大差别为一,所以它也被称为平衡二叉树.下面是平衡二叉树和非平衡二叉树对比的例图: 平衡因子(bf):结点的左子树的深度减去右子树的深度,那么显然-1<=bf<=1; AVL树的作用: 我们知道,对于一般的二叉搜索树(Binary Search Tree),其期望高度(即为一棵平衡树时)为