AVL Trees.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
AVL Trees.ppt

AVL Trees CSE, POSTECH Balanced Binary Search Trees If the height of a binary tree is always O(log n), we can guarantee O(log n) performance for each search tree operation Trees with a worst-case height of O(log n) are called balanced trees An example of a balanced tree is AVL (Adelson-Velsky and Landis) tree AVL Tree Definition Binary tree. If T is a nonempty binary tree with TL and TR as its left and right subtrees, then T is an AVL tree iff TL and TR are AVL trees, and |hL – hR| ? 1 where hL and hR are the heights of TL and TR, respectively AVL Search Trees An AVL search tree is a binary search tree that is also an AVL tree Which trees in Figure 14.1 are AVL trees? (a) and (b) Which trees in Figure 14.1 are AVL search trees? (b) only Which trees in Figure 14.3 are AVL search trees? (a) and (b) Indexed AVL Search Trees An indexed AVL search tree is an indexed binary search tree that is also an AVL tree Which trees in Figure 14.2 are indexed AVL trees? (a) and (b) Which trees in Figure 14.2 are indexed AVL search trees? (a) and (b) Properties of AVL Tree The height of an AVL tree with n nodes is O(log n) For every value of n, n ? 0, there exists an AVL tree An n-node AVL search tree can be searched in O(height) = O(log n) time A new node can be inserted into an n-node AVL search tree so that the result is an n+1 node AVL tree and insertion can be done in O(log n) time A node can be deleted from an n-node AVL search tree, n0, so that the result is an n-1 node AVL tree and deletion can be done in O(log n) time Balance Factor AVL trees are normally represented using the linked representation To facilitate insertion and deletion, a balance factor (bf) is associated with each node The balance factor bf(x) of a node x is defined as height(x?leftChild) – height(x?rightChild) Balance factor of each node in an AVL tree must be –1, 0, or 1 See Figure 15.1 for examples AVL Tree with Balance Factors Is this an AVL tree? What is the balance factor for each node in this A

文档评论(0)

gshshxx + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档