1. 2-3 tree
a) Allow 1 or 2 keys per node.
1) 2-node: one key, two children.
2) 3-node: two keys, three children.
b) Perfect balance: Every path from root to null link has same length.
c) Symmetric order: Inorder traversal yields keys in ascending order.
2. Search.
a) Compare search key against keys in node.
b) Find interval containing search key.
c) Follow associated link (recursively).
3. Insertion into a 3-node at bottom.
a) Add new key to 3-node to create temporary 4-node.
b) Move middle key in 4-node into parent.
c) Repeat up the tree, as necessary.
d) If you reach the root and it's a 4-node, split it into two 2-nodes.
Invariants: Maintains symmetric order and perfect balance.
4. Tree height.
a) Worst case: lg N. [all 2-nodes]
b) Best case: log3 N ≈ .631 lg N. [all 3-nodes]
c) Guaranteed logarithmic performance for search and insert.
5. Left-leaning red-black BSTs
a) Represent 2–3 tree as a BST.
b) Use "internal" left-leaning links as "glue" for 3–nodes.
6. An equivalent definition :
A BST such that:
a) No node has two red links connected to it. ( no consecutive red nodes on any path)
b) Every path from root to null link has the same number of black links. ( same # of black nodes on any path)
c) Red links lean left.
7. Observations of Left-leaning red-black BSTs:
a) 1–1 correspondence between 2–3 and LLRB.
b) Search is the same as for elementary BST (ignore color).
c) Each node is pointed to by precisely one link (from its parent) ⇒ can encode color of links in nodes.
8. Elementary red-black BST operations
a) Left rotation: Orient a (temporarily) right-leaning red link to lean left:
private Node rotateLeft(Node h) { assert isRed(h.right); Node x = h.right; h.right = x.left; x.left = h; x.color = h.color; h.color = RED; return x; }
b) Right rotation: Orient a left-leaning red link to (temporarily) lean right.
private Node rotateRight(Node h) { assert isRed(h.left); Node x = h.left; h.left = x.right; x.right = h; x.color = h.color; h.color = RED; return x; }
c) Color flip: Recolor to split a (temporary) 4-node.
private void flipColors(Node h) { assert !isRed(h); assert isRed(h.left); assert isRed(h.right); h.color = RED; h.left.color = BLACK; h.right.color = BLACK; }
8. Insertion in a LLRB tree:
a) Basic strategy. Maintain 1-1 correspondence with 2-3 trees by applying elementary red-black BST operations.
b) Case 1. Insert into a 2-node at the bottom.
1) Do standard BST insert; color new link red.
2) If new red link is a right link, rotate left.
c) Case 2. Insert into a 3-node at the bottom.
1) Do standard BST insert; color new link red.
2) Rotate to make lean left (if needed).
3) Rotate to balance the 4-node (if needed).
4) Flip colors to pass red link up one level.
5) Repeat case 1 or case 2 up the tree (if needed).
d) Same code for all cases.
1) Right child red, left child black: rotate left.
2) Left child, left-left grandchild red: rotate right.
3) Both children red: flip colors.
private Node put(Node h, Key key, Value val) { if (h == null) return new Node(key, val, RED); int cmp = key.compareTo(h.key); if (cmp < 0) h.left = put(h.left, key, val); else if (cmp > 0) h.right = put(h.right, key, val); else if (cmp == 0) h.val = val; if (isRed(h.right) && !isRed(h.left)) h = rotateLeft(h); if (isRed(h.left) && isRed(h.left.left)) h = rotateRight(h); if (isRed(h.left) && isRed(h.right)) flipColors(h); return h; }
9. Symbol Table Implementation Summary :
10. B-tree :
a) Generalize 2-3 trees by allowing up to M - 1 key-link pairs per node.
(choose M as large as possible so that M links fit in a page.)
b) At least 2 key-link pairs at root.
c) At least M / 2 key-link pairs in other nodes.
d) External nodes contain client keys.
e) Internal nodes contain copies of keys to guide search.
11. Search in a B-tree:
a) Start at root.
b) Find interval for search key and take corresponding link.
c) Search terminates in external node.
12. Insert in a B-tree:
a) Search for new key.
b) Insert at bottom.
c) Split nodes with M key-link pairs on the way up the tree.
13. Balance in B-tree:
a) A search or an insertion in a B-tree of order M with N keys requires between log M-1 ( N ) and log M/2 ( N ) probes. (Pf. All internal nodes except root have between M / 2 and M - 1 links.)
b) Optimization : Always keep root page in memory.
相关推荐
在二叉搜索树(Binary Search Tree,BST)中,如果树高度失衡,例如变成一个链式结构,搜索效率会大幅下降。而平衡二叉树通过保持高度平衡,确保了在最坏情况下依然能保持O(log n)的时间复杂度进行查找、插入和删除...
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...
3. **平衡查找树(Balanced Search Tree, BST)**:如AVL树和红黑树等,它们确保了在最坏情况下的操作效率。文章中提到了对平衡树的旋转操作,如左旋、右旋以及双旋,这些操作用于维护树的平衡。 4. **最小生成树...
平衡二叉树(Balanced Binary Tree)是一种特殊的二叉树数据结构,它的主要特性在于保持了树的高度平衡。这种平衡状态使得在二叉查找树(Binary Search Tree, BST)中的操作,如插入、删除和搜索等,都能在对数时间...
- **二叉树(Binary Tree)或平衡查找树(Balanced Search Tree)**:用于快速查找和排序单词,例如AVL树或红黑树,以提高查询效率。 - **哈希表(Hash Table)**:可能用于存储文档ID和对应的关键词哈希,提供O...
平衡搜索树(Balanced Search Tree)是计算机科学中一种重要的数据结构,特别是在算法和数据库领域广泛应用。这种数据结构是二叉搜索树(Binary Search Tree, BST)的一个变体,它保持了二叉搜索树的基本特性,即左...
#### 1.1 二叉搜索树(Binary Search Tree) 二叉搜索树是一种重要的高级数据结构,支持多种动态集合操作,如查找、最小值、最大值、前驱、后继、插入和删除等。二叉搜索树可以作为字典或优先队列使用。 - **组织...
B+树和B树是两种常见的自平衡查找树(Balanced Search Tree)数据结构,常用于数据库和文件系统的索引存储。它们的设计目标是优化磁盘I/O操作,因为磁盘读写速度远慢于内存。在大数据量存储时,这种数据结构能有效...
为了解决这个问题,出现了几种平衡二叉搜索树(Balanced Binary Search Tree),如AVL树和红黑树: - **AVL树**:AVL树要求任何节点的两个子树的高度差不超过1,通过旋转操作(左旋、右旋)来保持平衡。 - **红黑...
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 ...
动态查找树主要有三种类型:二叉查找树(Binary Search Tree)、平衡二叉查找树(Balanced Binary Search Tree)和B-tree/B+-tree。这些树结构的查找时间复杂度为O(log2N),与树的深度相关。但是,在大规模数据存储...
- **平衡二叉树(Balanced Binary Tree)**:如AVL树和红黑树,保持左右子树高度平衡,确保搜索效率。 - **B树与B+树**:常用于数据库和文件系统,支持高效的范围查询和插入操作。 - **哈夫曼树(Huffman Tree)*...
6. **二叉搜索树(Binary Search Tree, BST)** - 左子树上的所有节点的值小于根节点的值,右子树上所有节点的值大于根节点的值。 - 支持快速查找、插入和删除操作。 7. **树的实现** - 在JavaScript中,可以...
- 平衡二叉树(Balanced Binary Tree):左右两个子树的高度差不超过1,并且每个节点都包含左子树和右子树。 - 红黑树(Red-Black Tree):一种自平衡二叉查找树,满足特定的颜色属性,保证了插入和删除操作的时间...
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...
5. **平衡二叉树(Balanced Binary Trees)**:为了优化查找效率,有时我们需要保持二叉树的高度平衡,例如AVL树和红黑树。这类平衡二叉树在插入和删除操作后,会自动调整以保持平衡。 6. **二叉堆(Binary Heap)*...
"Balanced_Binary_Tree.hpp"可能包含了某种平衡二叉树的实现。 线程二叉树(Threaded Binary Tree)是另一种优化的二叉树,它通过在每个节点上增加指向其前驱或后继节点的线索,使得在树中进行遍历时无需额外的数据...
- **平衡Kd树(Balanced Kd-tree)**:通过调整分割策略,使得树的深度和分支因子相对均衡,提高查询效率。 - **分裂策略优化**:除了使用中位数分割,还可以尝试最小最大分割、平均分割等方法。 - **剪枝技术**:在...
- **二叉搜索树(Binary Search Tree, BST)**: 左子树中的所有节点值小于父节点,右子树中的所有节点值大于父节点。 3. **树的遍历** - **前序遍历(Preorder Traversal)**: 访问根节点 -> 左子树 -> 右子树。 ...
- **二叉搜索树**(Binary Search Tree): 对于任意节点,其左子树中的所有节点的值小于该节点的值,其右子树中的所有节点的值大于该节点的值。 ##### 1.3 二叉树的表示方法 在编程语言中,二叉树通常通过结构体或类...