B + -Trees Same structure as B-trees. Dictionary pairs are in leaves only. Leaves form a doubly-linked list. Remaining nodes have following structure:

Slides:



Advertisements
Similar presentations
Splay Trees Binary search trees.
Advertisements

COL 106 Shweta Agrawal and Amit Kumar
Trees Types and Operations
Binary Tries (continued) split(k). Similar to split algorithm for unbalanced binary search trees. Construct S and B on way down the trie. Follow with a.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
Digital Search Trees & Binary Tries Analog of radix sort to searching. Keys are binary bit strings.  Fixed length – 0110, 0010, 1010,  Variable.
Data Structures: Trees i206 Fall 2010 John Chuang Some slides adapted from Marti Hearst, Brian Hayes, or Glenn Brookshear.
Higher Order Tries Key = Social Security Number.   9 decimal digits. 10-way trie (order 10 trie) Height
Data Structures and Algorithms1 B-Trees with Minimum=1 2-3 Trees.
Digital Search Trees & Binary Tries Analog of radix sort to searching. Keys are binary bit strings.  Fixed length – 0110, 0010, 1010,  Variable.
B + -Trees Same structure as B-trees. Dictionary pairs are in leaves only. Leaves form a doubly-linked list. Remaining nodes have following structure:
Patricia P ractical A lgorithm T o R etrieve I nformation C oded I n A lphanumeric. Compressed binary trie. All nodes are of the same data type (binary.
Red Black Trees Colored Nodes Definition Binary search tree.
Binomial Heaps. Min Binomial Heap Collection of min trees
CSE 326: Data Structures B-Trees Ben Lerner Summer 2007.
Balanced Trees. Binary Search tree with a balance condition Why? For every node in the tree, the height of its left and right subtrees must differ by.
Bottom-Up Splay Trees–Analysis Actual and amortized complexity of join is O(1). Amortized complexity of search, insert, delete, and split is O(log n).
B-Trees (continued) Analysis of worst-case and average number of disk accesses for an insert. Delete and analysis. Structure for B-tree node.
B-Trees Large degree B-trees used to represent very large dictionaries that reside on disk. Smaller degree B-trees used for internal-memory dictionaries.
Binary Trees Chapter 6.
Advanced Data Structures and Algorithms COSC-600 Lecture presentation-6.
B-Tree. B-Trees a specialized multi-way tree designed especially for use on disk In a B-tree each node may contain a large number of keys. The number.
B+ Trees COMP
1 B Trees - Motivation Recall our discussion on AVL-trees –The maximum height of an AVL-tree with n-nodes is log 2 (n) since the branching factor (degree,
2-3 Trees Extended tree.  Tree in which all empty subtrees are replaced by new nodes that are called external nodes.  Original nodes are called internal.
Multi-way Trees. M-way trees So far we have discussed binary trees only. In this lecture, we go over another type of tree called m- way trees or trees.
Chapter 6 Binary Trees. 6.1 Trees, Binary Trees, and Binary Search Trees Linked lists usually are more flexible than arrays, but it is difficult to use.
Data Structures Balanced Trees 1CSCI Outline  Balanced Search Trees 2-3 Trees Trees Red-Black Trees 2CSCI 3110.
2-3 Tree. Slide 2 Outline  Balanced Search Trees 2-3 Trees Trees.
Binary Search Tree vs. Balanced Search Tree. Why care about advanced implementations? Same entries, different insertion sequence: 10,20,30,40,50,60,70,
Balanced Search Trees Problem: Efficiency of BST is related to tree’s height.  search, insert and remove follow a path from root to desired location 
School of Engineering and Computer Science Victoria University of Wellington Copyright: Xiaoying Gao, Peter Andreae, VUW B Trees and B+ Trees COMP 261.
File Organization and Processing Week Tree Tree.
2-3 Trees Extended tree.  Tree in which all empty subtrees are replaced by new nodes that are called external nodes.  Original nodes are called internal.
B-Tree – Delete Delete 3. Delete 8. Delete
Lecture 11COMPSCI.220.FS.T Balancing an AVLTree Two mirror-symmetric pairs of cases to rebalance the tree if after the insertion of a new key to.
B-Trees ( Rizwan Rehman) Large degree B-trees used to represent very large dictionaries that reside on disk. Smaller degree B-trees used for internal-memory.
1 Chapter 7 Objectives Upon completion you will be able to: Create and implement binary search trees Understand the operation of the binary search tree.
Binary Search Trees (BSTs) 18 February Binary Search Tree (BST) An important special kind of binary tree is the BST Each node stores some information.
Binary Tree. Some Terminologies Short review on binary tree Tree traversals Binary Search Tree (BST)‏ Questions.
Bottom-Up Red-Black Trees Top-down red-black trees require O(log n) rotations per insert/delete. Color flips cheaper than rotations. Priority search trees.
Dynamic Dictionaries Primary Operations:  get(key) => search  put(key, element) => insert  remove(key) => delete Additional operations:  ascend()
Heaps © 2010 Goodrich, Tamassia. Heaps2 Priority Queue ADT  A priority queue (PQ) stores a collection of entries  Typically, an entry is a.
2 Binary Heaps What if we’re mostly concerned with finding the most relevant data?  A binary heap is a binary tree (2 or fewer subtrees for each node)
More Trees. Outline Tree B-Tree 2-3 Tree Tree Red-Black Tree.
COMP261 Lecture 23 B Trees.
File Organization and Processing Week 3
Red Black Trees Colored Nodes Definition Binary search tree.
Red Black Trees Colored Nodes Definition Binary search tree.
Multiway Search Trees Data may not fit into main memory
B+-Trees j a0 k1 a1 k2 a2 … kj aj j = number of keys in node.
B-Trees Large degree B-trees used to represent very large dictionaries that reside on disk. Smaller degree B-trees used for internal-memory dictionaries.
Splay Trees Binary search trees.
Heaps © 2010 Goodrich, Tamassia Heaps Heaps
Digital Search Trees & Binary Tries
Splay Trees Binary search trees.
Patricia Practical Algorithm To Retrieve Information Coded In Alphanumeric. Compressed binary trie. All nodes are of the same data type (binary tries use.
B-Trees (continued) Analysis of worst-case and average number of disk accesses for an insert. Delete and analysis. Structure for B-tree node.
Height Balanced Trees 2-3 Trees.
Binary Tries (continued)
Digital Search Trees & Binary Tries
Binary Search Trees.
Binary Trees, Binary Search Trees
B-Trees Large degree B-trees used to represent very large dictionaries that reside on disk. Smaller degree B-trees used for internal-memory dictionaries.
2-3 Trees Extended tree. Tree in which all empty subtrees are replaced by new nodes that are called external nodes. Original nodes are called internal.
B+-Trees j a0 k1 a1 k2 a2 … kj aj j = number of keys in node.
B-Trees Large degree B-trees used to represent very large dictionaries that reside on disk. Smaller degree B-trees used for internal-memory dictionaries.
Binary Trees, Binary Search Trees
Red Black Trees Colored Nodes Definition Binary search tree.
Splay Trees Binary search trees.
Presentation transcript:

B + -Trees Same structure as B-trees. Dictionary pairs are in leaves only. Leaves form a doubly-linked list. Remaining nodes have following structure: j a 0 k 1 a 1 k 2 a 2 … k j a j j = number of keys in node. a i is a pointer to a subtree. k i largest in a i-1.

Example B+-tree  index node  leaf/data node

B+-tree—Search key = 5 6 <= key <= 20

B+-tree—Insert Insert 10 1

16 30 Insert Insert a pair with key = 2. New pair goes into a 3-node

Insert Into A 3-node Insert new pair so that the keys are in ascending order. Split into two nodes Insert smallest key in new node and pointer to this new node into parent

9 Insert Insert an index entry 2 plus a pointer into parent

Insert Now, insert a pair with key =

Insert Now, insert a pair with key = Insert an index entry17 plus a pointer into parent.

Insert Now, insert a pair with key = Insert an index entry17 plus a pointer into parent

Insert Now, insert a pair with key =

Delete Delete pair with key = Note: delete pair is always in a leaf.

Delete Delete pair with key = Note: delete pair is always in a leaf. 17

Delete Delete pair with key = Get >= 1 from sibling and update parent key.

Delete Delete pair with key = Get >= 1 from sibling and update parent key. 3

Delete Delete pair with key = Merge with sibling, delete in-between key in parent. 3

Delete Delete pair with key = Get >= 1 from sibling and update parent key. 5

Delete Delete pair with key = Merge with sibling, delete in-between key in parent. 6 6

Delete

Delete Delete pair with key = Merge with sibling, delete in-between key in parent. 6 6

Delete Index node becomes deficient Get >= 1 from sibling, move last one to parent, get parent key.

Delete Delete Merge with sibling, delete in-between key in parent. 9

Delete Index node becomes deficient Merge with sibling and in-between key in parent.

Delete Index node becomes deficient It’s the root; discard

B*-Trees Root has between 2 and 2 * floor((2m – 2)/3) + 1 children. Remaining nodes have between ceil((2m – 1)/3) and m children. All external/failure nodes are on the same level.

Insert When insert node is overfull, check adjacent sibling. If adjacent sibling is not full, move a dictionary pair from overfull node, via parent, to nonfull adjacent sibling. If adjacent sibling is full, split overfull node, adjacent full node, and in-between pair from parent to get three nodes with floor((2m – 2)/3), floor((2m – 1)/3), floor(2m/3) pairs plus two additional pairs for insertion into parent.

Delete When combining, must combine 3 adjacent nodes and 2 in-between pairs from parent.  Total # pairs involved = 2 * floor((2m-2)/3) + [floor((2m-2)/3) – 1] + 2.  Equals 3 * floor((2m-2)/3) + 1. Combining yields 2 nodes and a pair that is to be inserted into the parent.  m mod 3 = 0 => nodes have m – 1 pairs each.  m mod 3 = 1 => one node has m – 1 pairs and the other has m – 2.  m mod 3 = 2 => nodes have m – 2 pairs each.

Splay Trees Binary search trees. Search, insert, delete, and split have amortized complexity O(log n) & actual complexity O(n). Actual and amortized complexity of join is O(1). Priority queue and double-ended priority queue versions outperform heaps, deaps, etc. over a sequence of operations. Two varieties.  Bottom up.  Top down.

Bottom-Up Splay Trees Search, insert, delete, and join are done as in an unbalanced binary search tree. Search, insert, and delete are followed by a splay operation that begins at a splay node. When the splay operation completes, the splay node has become the tree root. Join requires no splay (or, a null splay is done). For the split operation, the splay is done in the middle (rather than end) of the operation.

Splay Node – search(k) If there is a pair whose key is k, the node containing this pair is the splay node. Otherwise, the parent of the external node where the search terminates is the splay node

Splay Node – insert(newPair) If there is already a pair whose key is newPair.key, the node containing this pair is the splay node. Otherwise, the newly inserted node is the splay node

Splay Node – delete(k) If there is a pair whose key is k, the parent of the node that is physically deleted from the tree is the splay node. Otherwise, the parent of the external node where the search terminates is the splay node

Splay Node – split(k) Use the unbalanced binary search tree insert algorithm to insert a new pair whose key is k. The splay node is as for the splay tree insert algorithm. Following the splay, the left subtree of the root is S, and the right subtree is B. S m B m is set to null if it is the newly inserted pair.

Splay Let q be the splay node. q is moved up the tree using a series of splay steps. In a splay step, the node q moves up the tree by 0, 1, or 2 levels. Every splay step, except possibly the last one, moves q two levels up.

Splay Step If q = null or q is the root, do nothing (splay is over). If q is at level 2, do a one-level move and terminate the splay operation. p q ab c bc a q p q right child of p is symmetric.

Splay Step If q is at a level > 2, do a two-level move and continue the splay operation. q right child of right child of gp is symmetric. p q ab c gp d cd b p q a

2-Level Move (case 2) q left child of right child of gp is symmetric. p q bc a gp d acb p q d

Per Operation Actual Complexity Start with an empty splay tree and insert pairs with keys 1, 2, 3, …, in this order

Per Operation Actual Complexity Start with an empty splay tree and insert pairs with keys 1, 2, 3, …, in this order

Per Operation Actual Complexity Worst-case height = n. Actual complexity of search, insert, delete, and split is O(n).

Digital Search Trees & Binary Tries Analog of radix sort to searching. Keys are binary bit strings.  Fixed length – 0110, 0010, 1010,  Variable length – 01, 00, 101, Application – IP routing, packet classification, firewalls.  IPv4 – 32 bit IP address.  IPv6 – 128 bit IP address.

Digital Search Tree Assume fixed number of bits. Not empty =>  Root contains one dictionary pair (any pair).  All remaining pairs whose key begins with a 0 are in the left subtree.  All remaining pairs whose key begins with a 1 are in the right subtree.  Left and right subtrees are digital subtrees on remaining bits.

Example Start with an empty digital search tree and insert a pair whose key is Now, insert a pair whose key is

Example Now, insert a pair whose key is

Example Now, insert a pair whose key is

Example Now, insert a pair whose key is

Search/Insert/Delete Complexity of each operation is O(#bits in a key). #key comparisons = O(height). Expensive when keys are very long

Binary Trie Information Retrieval. At most one key comparison per operation. Fixed length keys.  Branch nodes. Left and right child pointers. No data field(s).  Element nodes. No child pointers. Data field to hold dictionary pair.

Example At most one key comparison for a search

Variable Key Length Left and right child fields. Left and right pair fields.  Left pair is pair whose key terminates at root of left subtree or the single pair that might otherwise be in the left subtree.  Right pair is pair whose key terminates at root of right subtree or the single pair that might otherwise be in the right subtree.  Field is null otherwise.

Example At most one key comparison for a search null

Fixed Length Insert Insert Zero compares.

Fixed Length Insert Insert

Fixed Length Insert Insert

Fixed Length Insert Insert One compare

Fixed Length Delete Delete

Fixed Length Delete Delete 0111.One compare

Fixed Length Delete Delete

Fixed Length Delete Delete

Fixed Length Delete Delete

Fixed Length Delete Delete

Fixed Length Delete Delete 1100.One compare

Compressed Binary Tries No branch node whose degree is 1. Add a bit# field to each branch node. bit# tells you which bit of the key to use to decide whether to move to the left or right subtrie.

Binary Trie bit# field shown in black outside branch node.

Compressed Binary Trie bit# field shown in black outside branch node.

Compressed Binary Trie #branch nodes = n – 1.

Insert Insert 0010.

Insert Insert

Insert

Delete Delete 0010.

Delete Delete 1001.

Delete