`
leonzhx
  • 浏览: 796713 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Balanced Search Tree

 
阅读更多

1.  Sorted Arrays: Supported Operations

   a) Search (binary search)  θ(log(n))

   b) Select (given order statistic i ) O(1)

   c) MIN/MAX O(1)

   d) Pred/Succ (given pointer/index to a key) O(1)

   e) Rank (i.e., # of keys less than or equal to a given value) O(log(n))

   f) Output in sorted order O(n)

   g) insertion and deletion θ(n) 

 

2.  Balanced Search Trees: Supported Operations

   a) Search θ(log(n))

   b) Select O(log(n))

   c) MIN/MAX O(log(n))

   d) Pred/Succ O(log(n))

   e) Rank O(log(n))

   f) Output in sorted order O(n)

   g) Insert/Delete O(log(n))

  Like sorted array + fast (logarithmic) inserts + deletes !

 

3.  Binary Search Tree Structure

  -- exactly one node per key

  -- most basic version :

     each node has

         -- left child pointer

         -- right child pointer

         -- parent pointer 

  -- for an arbitrary node , it's bigger than any nodes in its left child tree and less than those in its right  child tree.

  Height of tree: longest root-leaf path

 

4.  Min, Max, Pred, And Succ

  To compute the minimum (maximum) key of a tree

  - Start at root

  - Follow left child (right child for maximum) untill you can't anymore

  - return last key found

 

5.  To compute the predecessor of key k

  - Easy case : If k’s left subtree nonempty, return max key in left subtree

  - Otherwise : follow parent pointers until you get to a key less than k.

 

6.  n-Order Traversal

  - Let r = root of search tree, with subtrees TL and TR

  - recurse on TL

  - Print out r’s key

  - Recurse on TR

 

7.  Deletion--To delete a key k from a search tree

  -- Search for k

  -- easy case : (k’s node has no children)

     --Just delete k’s node from tree

  -- mediaum case : (k’s node has one child)

     --Unique child assumes position previously held by k’s node

  -- difficult case : (k’s node has 2 children)

     --Compute k’s predecessor i

     -- Swap k and i (in it’s new position, k has no right child )

 

8.  Select and Rank

     Idea : store the size of the node at each node

     size(x) = # of tree nodes in subtree rooted at x.

     if x has children y and z, then size(y) + size(z) + 1

     Easy to keep sizes up-to-date during an Insertion or Deletion

     To select ith order statistic from augmented search tree (with subtree sizes)

 

      -- start at root x, with children y and z

      -- let a = size(y) [a = 0 if x has no left child ]

      -- if a = i-1, return x’s key

      -- if a >= i, recursively compute ith order statistic of search tree rooted at y

      -- if a < i-1 recursively compute (i-a-1)th order statistic of search tree rooted at z

 

9.  Balanced Search Trees :

    Idea : ensure that height is always O(log(n)) [best possible]

    Search / Insert / Delete / Min / Max / Pred / Succ will then run in O(log(n)) time [n = # of keys in tree]

 

10.  Red-Black Tree Invariants

    a) Each node red or black

    b) Root is black

    c) No 2 reds in a row [ red node => only black children ]

    d) Every root-NULL path has same number of black nodes

 

11.  Height Guarantee

    Claim : every red-black tree with n nodes has height <= 2log2(n+1)

    Proof : If every root-NUL path has >= k nodes, then tree includes (at the top) a perfectly balanced search tree of depth k-1. => Size n of the tree must be at least 2^k -1.  => k <= log2(n+1)



          Thus in a red-black tree with n nodes, there is a root-NULL path (the shortest path) with at most log2(n+1) black nodes.

                By 4th Invariant : every root-NULL path has black nodes at most log2(n+1)

                By 3rd Invariant : every root-NULL path has at most 2log2(n+1) total nodes.

 

12.  Key primitive for balanced search tree : common to all balanced search tree such as AVL, Red-Black, B+, etc. Locally balance subtrees at a node in O(1) time.

       

 

 

  • 大小: 11.7 KB
  • 大小: 30.2 KB
分享到:
评论

相关推荐

    leetcode的题目:Balanced Binary Tree

    在二叉搜索树(Binary Search Tree,BST)中,如果树高度失衡,例如变成一个链式结构,搜索效率会大幅下降。而平衡二叉树通过保持高度平衡,确保了在最坏情况下依然能保持O(log n)的时间复杂度进行查找、插入和删除...

    Serach Engine (simple example)

    it contains of balanced search tree,index inverted,GPS data processing and so on.the balanced search tree was built on AVL tree algorithm with node of meta data index inverted. It implemented the key...

    Thesis2013-浅谈数据结构题的几个非经典解法1

    3. **平衡查找树(Balanced Search Tree, BST)**:如AVL树和红黑树等,它们确保了在最坏情况下的操作效率。文章中提到了对平衡树的旋转操作,如左旋、右旋以及双旋,这些操作用于维护树的平衡。 4. **最小生成树...

    pinghen.rar_avl_avl tree_balanced tree_二叉树_平衡二叉树

    平衡二叉树(Balanced Binary Tree)是一种特殊的二叉树数据结构,它的主要特性在于保持了树的高度平衡。这种平衡状态使得在二叉查找树(Binary Search Tree, BST)中的操作,如插入、删除和搜索等,都能在对数时间...

    自制小的文字搜索引擎

    - **二叉树(Binary Tree)或平衡查找树(Balanced Search Tree)**:用于快速查找和排序单词,例如AVL树或红黑树,以提高查询效率。 - **哈希表(Hash Table)**:可能用于存储文档ID和对应的关键词哈希,提供O...

    MIT算法导论公开课之课程笔记 平衡搜索树.rar

    平衡搜索树(Balanced Search Tree)是计算机科学中一种重要的数据结构,特别是在算法和数据库领域广泛应用。这种数据结构是二叉搜索树(Binary Search Tree, BST)的一个变体,它保持了二叉搜索树的基本特性,即左...

    陈启峰《Size Balanced Tree》 pdf英文版

    #### 1.1 二叉搜索树(Binary Search Tree) 二叉搜索树是一种重要的高级数据结构,支持多种动态集合操作,如查找、最小值、最大值、前驱、后继、插入和删除等。二叉搜索树可以作为字典或优先队列使用。 - **组织...

    B+,B树窗口图形程序

    B+树和B树是两种常见的自平衡查找树(Balanced Search Tree)数据结构,常用于数据库和文件系统的索引存储。它们的设计目标是优化磁盘I/O操作,因为磁盘读写速度远慢于内存。在大数据量存储时,这种数据结构能有效...

    BST.zip_binary search tree_tree

    为了解决这个问题,出现了几种平衡二叉搜索树(Balanced Binary Search Tree),如AVL树和红黑树: - **AVL树**:AVL树要求任何节点的两个子树的高度差不超过1,通过旋转操作(左旋、右旋)来保持平衡。 - **红黑...

    NOI国家集训队2007年论文 陈启峰《Size Balanced Tree》

    Before presenting Size Balanced Trees it is necessary to explicate Binary Search Trees and rotations on BSTs, Left-Rotate and Right-Rotate. ——Zhongshan Memorial Middle School, Guangdong, China ...

    B-tree与B+tree简介

    动态查找树主要有三种类型:二叉查找树(Binary Search Tree)、平衡二叉查找树(Balanced Binary Search Tree)和B-tree/B+-tree。这些树结构的查找时间复杂度为O(log2N),与树的深度相关。但是,在大规模数据存储...

    tree树形结构

    - **平衡二叉树(Balanced Binary Tree)**:如AVL树和红黑树,保持左右子树高度平衡,确保搜索效率。 - **B树与B+树**:常用于数据库和文件系统,支持高效的范围查询和插入操作。 - **哈夫曼树(Huffman Tree)*...

    js 树结构 tree

    6. **二叉搜索树(Binary Search Tree, BST)** - 左子树上的所有节点的值小于根节点的值,右子树上所有节点的值大于根节点的值。 - 支持快速查找、插入和删除操作。 7. **树的实现** - 在JavaScript中,可以...

    Javatree java树结构

    - 平衡二叉树(Balanced Binary Tree):左右两个子树的高度差不超过1,并且每个节点都包含左子树和右子树。 - 红黑树(Red-Black Tree):一种自平衡二叉查找树,满足特定的颜色属性,保证了插入和删除操作的时间...

    数据结构Advanced-Data-Structures

    Weight-balanced tree 185 Threaded binary tree 186 AVL tree 191 Red-black tree 195 AA tree 210 Scapegoat tree 215 Splay tree 219 T-tree 234 Rope 237 Top Trees 242 Tango Trees 246 Van Emde Boas tree 268...

    java-二叉树binaryTree

    5. **平衡二叉树(Balanced Binary Trees)**:为了优化查找效率,有时我们需要保持二叉树的高度平衡,例如AVL树和红黑树。这类平衡二叉树在插入和删除操作后,会自动调整以保持平衡。 6. **二叉堆(Binary Heap)*...

    Binary-Tree.7z

    "Balanced_Binary_Tree.hpp"可能包含了某种平衡二叉树的实现。 线程二叉树(Threaded Binary Tree)是另一种优化的二叉树,它通过在每个节点上增加指向其前驱或后继节点的线索,使得在树中进行遍历时无需额外的数据...

    kdtree代码

    - **平衡Kd树(Balanced Kd-tree)**:通过调整分割策略,使得树的深度和分支因子相对均衡,提高查询效率。 - **分裂策略优化**:除了使用中位数分割,还可以尝试最小最大分割、平均分割等方法。 - **剪枝技术**:在...

    JAVA制作树TREE

    - **二叉搜索树(Binary Search Tree, BST)**: 左子树中的所有节点值小于父节点,右子树中的所有节点值大于父节点。 3. **树的遍历** - **前序遍历(Preorder Traversal)**: 访问根节点 -&gt; 左子树 -&gt; 右子树。 ...

    二叉树详解 binary tree

    - **二叉搜索树**(Binary Search Tree): 对于任意节点,其左子树中的所有节点的值小于该节点的值,其右子树中的所有节点的值大于该节点的值。 ##### 1.3 二叉树的表示方法 在编程语言中,二叉树通常通过结构体或类...

Global site tag (gtag.js) - Google Analytics