Each internal node v with d(v) children stores d 1 keys. k i 1 < key in i-th sub-tree k i, where we use k 0 = and k d =.

Similar documents
8 Priority Queues. 8 Priority Queues. Prim s Minimum Spanning Tree Algorithm. Dijkstra s Shortest Path Algorithm

The null-pointers in a binary search tree are replaced by pointers to special null-vertices, that do not carry any object-data

7 Dictionary. Ernst Mayr, Harald Räcke 126

7 Dictionary. Harald Räcke 125

Part III. Data Structures. Abstract Data Type. Dynamic Set Operations. Dynamic Set Operations

9 Union Find. 9 Union Find. List Implementation. 9 Union Find. Union Find Data Structure P: Maintains a partition of disjoint sets over elements.

So far we have implemented the search for a key by carefully choosing split-elements.

7 Dictionary. EADS c Ernst Mayr, Harald Räcke 109

7.3 AVL-Trees. Definition 15. Lemma 16. AVL-trees are binary search trees that fulfill the following balance condition.

Part II. Foundations. Ernst Mayr, Harald Räcke 16

7 Dictionary. 7.1 Binary Search Trees. Binary Search Trees: Searching. 7.1 Binary Search Trees

Part V. Matchings. Matching. 19 Augmenting Paths for Matchings. 18 Bipartite Matching via Flows

10 van Emde Boas Trees

16. Binary Search Trees. [Ottman/Widmayer, Kap. 5.1, Cormen et al, Kap ]

16. Binary Search Trees. [Ottman/Widmayer, Kap. 5.1, Cormen et al, Kap ]

Chapter 5 Data Structures Algorithm Theory WS 2017/18 Fabian Kuhn

Dictionary: an abstract data type

Binary Search Trees. Motivation

Binary Search Trees. Lecture 29 Section Robb T. Koether. Hampden-Sydney College. Fri, Apr 8, 2016

Dictionary: an abstract data type

Optimal Color Range Reporting in One Dimension

Fibonacci Heaps These lecture slides are adapted from CLRS, Chapter 20.

Assignment 5: Solutions

Part I. Efficient Algorithms and Data Structures. Organizational Matters. Part I. Organizational Matters WS 2013/14. Harald Räcke. Winter Term 2013/14

ICS 252 Introduction to Computer Design

Problem: Data base too big to fit memory Disk reads are slow. Example: 1,000,000 records on disk Binary search might take 20 disk reads

Binary Decision Diagrams. Graphs. Boolean Functions

Nearest Neighbor Search with Keywords

HW #4. (mostly by) Salim Sarımurat. 1) Insert 6 2) Insert 8 3) Insert 30. 4) Insert S a.

Adding Relations in Multi-levels to an Organization Structure of a Complete Binary Tree Maximizing Total Shortening Path Length

Lecture Lecture 3 Tuesday Sep 09, 2014

Inge Li Gørtz. Thank you to Kevin Wayne for inspiration to slides

Advanced Implementations of Tables: Balanced Search Trees and Hashing

ENS Lyon Camp. Day 2. Basic group. Cartesian Tree. 26 October

INF2220: algorithms and data structures Series 1

Binary Decision Diagrams

Fundamental Algorithms

CS 240 Data Structures and Data Management. Module 4: Dictionaries

4.8 Huffman Codes. These lecture slides are supplied by Mathijs de Weerd

Splay Trees. CMSC 420: Lecture 8

1. Introduction Bottom-Up-Heapsort is a variant of the classical Heapsort algorithm due to Williams ([Wi64]) and Floyd ([F64]) and was rst presented i

Data Structures and and Algorithm Xiaoqing Zheng

A Lecture on Hashing. Aram-Alexandre Pooladian, Alexander Iannantuono March 22, Hashing. Direct Addressing. Operations - Simple

Algorithms and Complexity Theory. Chapter 8: Introduction to Complexity. Computer Science - Durban - September 2005

CS Data Structures and Algorithm Analysis

Data Structures and Algorithms " Search Trees!!

Lecture 18: Oct 15, 2014

past balancing schemes require maintenance of balance info at all times, are aggresive use work of searches to pay for work of rebalancing

Tree-width and algorithms

AVL trees. AVL trees

Fundamental Algorithms

Algorithms Theory. 08 Fibonacci Heaps

Search Trees. EECS 2011 Prof. J. Elder Last Updated: 24 March 2015

Fixed-Universe Successor : Van Emde Boas. Lecture 18

5 Spatial Access Methods

Dynamic Programming on Trees. Example: Independent Set on T = (V, E) rooted at r V.

Proof methods and greedy algorithms

Context-Free Languages

Optimal Tree-decomposition Balancing and Reachability on Low Treewidth Graphs

Heaps and Priority Queues

DS L19: B Trees

5 Spatial Access Methods

Premaster Course Algorithms 1 Chapter 3: Elementary Data Structures

Wolf-Tilo Balke Silviu Homoceanu Institut für Informationssysteme Technische Universität Braunschweig

Binary Decision Diagrams

Data Structures 1 NTIN066

Search Trees. Chapter 10. CSE 2011 Prof. J. Elder Last Updated: :52 AM

Data Structures 1 NTIN066

Ordered Dictionary & Binary Search Tree

8: Splay Trees. Move-to-Front Heuristic. Splaying. Splay(12) CSE326 Spring April 16, Search for Pebbles: Move found item to front of list

Minimum Cut in a Graph Randomized Algorithms

CSE 591 Foundations of Algorithms Homework 4 Sample Solution Outlines. Problem 1

Weak Heaps and Friends: Recent Developments

Design and Analysis of Algorithms

Multimedia Databases 1/29/ Indexes for Multimedia Data Indexes for Multimedia Data Indexes for Multimedia Data

25. Minimum Spanning Trees

25. Minimum Spanning Trees

Lecture 17: Trees and Merge Sort 10:00 AM, Oct 15, 2018

AVL Trees. Manolis Koubarakis. Data Structures and Programming Techniques

Finding a Heaviest Triangle is not Harder than Matrix Multiplication

CS60007 Algorithm Design and Analysis 2018 Assignment 1

This lecture covers Chapter 7 of HMU: Properties of CFLs

RECOVERING NORMAL NETWORKS FROM SHORTEST INTER-TAXA DISTANCE INFORMATION

Note about the upper chromatic number of mixed hypertrees

Fibonacci (Min-)Heap. (I draw dashed lines in place of of circular lists.) 1 / 17

Evolutionary Tree Analysis. Overview

Nearest Neighbor Search with Keywords: Compression

Design and Analysis of Algorithms Recurrence. Prof. Chuhua Xian School of Computer Science and Engineering

Splay Trees. Splay Trees. Splay Trees. Splay Trees

CS 151. Red Black Trees & Structural Induction. Thursday, November 1, 12

Chapter 6. Self-Adjusting Data Structures

Dijkstra s Single Source Shortest Path Algorithm. Andreas Klappenecker

16. Binary Search Trees

Advanced Algorithms (2IL45)

Approximation of smallest linear tree grammar

Search and Lookahead. Bernhard Nebel, Julien Hué, and Stefan Wölfl. June 4/6, 2012

Using Aspect-Oriented Programming in the Development of a Multi-strategy Theorem Prover

Digital search trees JASS

Using preprocessing to speed up Brandes betweenness centrality algorithm

On the Isomorphism Problem for Decision Trees and Decision Lists

Transcription:

7.5 (a, b)-trees 7.5 (a, b)-trees Definition For b a an (a, b)-tree is a search tree with the following properties. all leaves have the same distance to the root. every internal non-root vertex v has at least a and at most b children 3. the root has degree at least if the tree is non-empty 4. the internal vertices do not contain data, but only keys (external search tree) Each internal node v with d(v) children stores d keys k,..., k d. The i-th subtree of v fulfills k i < key in i-th sub-tree k i, where we use k 0 = and k d =. 5. there is a special dummy leaf node with key-value 5. Oct. 08 Ernst Mayr, Harald Räcke 90/0 Ernst Mayr, Harald Räcke 9/0 7.5 (a, b)-trees 7.5 (a, b)-trees Example 0 9 Variants The dummy leaf element may not exist; it only makes implementation more convenient. 3 5 3 5 0 Variants in which b = a are commonly referred to as B-trees. A B-tree usually refers to the variant in which keys and data are stored at internal nodes. A B + tree stores the data only at leaf nodes as in our definition. Sometimes the leaf nodes are also connected in a linear list data structure to speed up the computation of successors and predecessors. A B tree requires that a node is at least /3-full as opposed to /-full (the requirement of a B-tree). Ernst Mayr, Harald Räcke 9/0 Ernst Mayr, Harald Räcke 93/0

Lemma 3 Let T be an (a, b)-tree for n > 0 elements (i.e., n + leaf nodes) and height h (number of edges from root to a leaf vertex). Then. a h n + b h. log b (n + ) h + log a ( n+ ) Search Search(8) 0 9 Proof. 3 5 If n > 0 the root has degree at least and all other nodes have degree at least a. This gives that the number of leaf nodes is at least a h. Analogously, the degree of any node is at most b and, hence, the number of leaf nodes at most b h. 3 5 0 The search is straightforward. It is only important that you need to go all the way to the leaf. Time: O(b h) = O(b log n), if the individual nodes are organized as linear lists. Ernst Mayr, Harald Räcke 94/0 Ernst Mayr, Harald Räcke 95/0 Search Search(9) 0 9 element x: 3 5 3 5 0 Follow the path as if searching for key[x]. If this search ends in leaf l, insert x before this leaf. For this add key[x] to the key-list of the last internal node v on the path. The search is straightforward. It is only important that you need to go all the way to the leaf. If after the insert v contains b nodes, do Rebalance(v). Time: O(b h) = O(b log n), if the individual nodes are organized as linear lists. Ernst Mayr, Harald Räcke 95/0 Ernst Mayr, Harald Räcke 96/0

Rebalance(v): Let k i, i =,..., b denote the keys stored in v. (7) Let j := b+ be the middle element. Create two nodes v, and v. v gets all keys k,..., k j and v gets keys k j+,..., k b. 3 0 9 Both nodes get at least b keys, and have therefore degree at least b + a since b a. They get at most b keys, and have therefore degree at most b + b (since b ). The key k j is promoted to the parent of v. The current pointer to v is altered to point to v, and a new pointer (to the right of k j ) in the parent is added to point to v. 3 5 6 8 5 6 8 0 Then, re-balance the parent. Ernst Mayr, Harald Räcke 97/0 Ernst Mayr, Harald Räcke 98/0 (7) (7) 3 0 9 3 6 0 9 5 6 7 8 5 7 8 3 5 6 7 8 0 3 5 6 7 8 0 Ernst Mayr, Harald Räcke 98/0 Ernst Mayr, Harald Räcke 98/0

Delete (7) 6 Delete element x (pointer to leaf vertex): 3 3 0 9 5 7 8 5 6 7 8 0 Let v denote the parent of x. If key[x] is contained in v, remove the key from v, and delete the leaf vertex. Otherwise delete the key of the predecessor of x from v; delete the leaf vertex; and replace the occurrence of key[x] in internal nodes by the predecessor key. (Note that it appears in exactly one internal vertex). If now the number of keys in v is below a perform Rebalance (v). Ernst Mayr, Harald Räcke 98/0 Ernst Mayr, Harald Räcke 99/0 Delete Delete Animation for deleting in an (a, b)-tree is only available in the lecture version of the slides. Rebalance (v): If there is a neighbour of v that has at least a keys take over the largest (if right neighbor) or smallest (if left neighbour) and the corresponding sub-tree. If not: merge v with one of its neighbours. The merged node contains at most (a ) + (a ) + keys, and has therefore at most a b successors. Then rebalance the parent. During this process the root may become empty. In this case the root is deleted and the height of the tree decreases. Ernst Mayr, Harald Räcke 00/0 Ernst Mayr, Harald Räcke 0/0

(, 4)-trees and red black trees There is a close relation between red-black trees and (, 4)-trees: (, 4)-trees and red black trees There is a close relation between red-black trees and (, 4)-trees: 7 7 4 8 0 5 4 4 8 0 5 4 3 5 3 8 9 7 43 47 3 5 3 8 9 7 43 47 3 4 5 8 3 7 8 9 0 5 7 4 43 47 First make it into an internal search tree by moving the satellite-data from the leaves to internal nodes. Add dummy leaves. Then, color one key in each internal node v black. If v contains 3 keys you need to select the middle key otherwise choose a black key arbitrarily. The other keys are colored red. Ernst Mayr, Harald Räcke 0/0 Ernst Mayr, Harald Räcke 0/0 (, 4)-trees and red black trees There is a close relation between red-black trees and (, 4)-trees: (, 4)-trees and red black trees There is a close relation between red-black trees and (, 4)-trees: 7 7 4 8 0 5 4 4 8 0 5 4 3 5 3 8 9 7 43 47 3 5 3 8 9 7 43 47 Re-attach the pointers to individual keys. A pointer that is between two keys is attached as a child of the red key. The incoming pointer, points to the black key. Note that this correspondence is not unique. In particular, there are different red-black trees that correspond to the same (, 4)-tree. Ernst Mayr, Harald Räcke 0/0 Ernst Mayr, Harald Räcke 0/0

Augmenting Data Structures Bibliography [MS08] [CLRS90] Kurt Mehlhorn, Peter Sanders: Algorithms and Data Structures The Basic Toolbox, Springer, 008 Thomas H. Cormen, Charles E. Leiserson, Ron L. Rivest, Clifford Stein: Introduction to algorithms (3rd ed.), MIT Press and McGraw-Hill, 009 A description of B-trees (a specific variant of (a, b)-trees) can be found in Chapter 8 of [CLRS90]. Chapter 7. of [MS08] discusses (a, b)-trees as discussed in the lecture. Ernst Mayr, Harald Räcke 03/0