Multi-way Search Trees

Similar documents
Red-Black, Splay and Huffman Trees

Multi-way Search Trees. (Multi-way Search Trees) Data Structures and Programming Spring / 25

B-Trees. Version of October 2, B-Trees Version of October 2, / 22

(2,4) Trees. 2/22/2006 (2,4) Trees 1

Module 4: Index Structures Lecture 13: Index structure. The Lecture Contains: Index structure. Binary search tree (BST) B-tree. B+-tree.

Trees. (Trees) Data Structures and Programming Spring / 28

(2,4) Trees Goodrich, Tamassia (2,4) Trees 1

CSE 530A. B+ Trees. Washington University Fall 2013

CS350: Data Structures Red-Black Trees

Self-Balancing Search Trees. Chapter 11

TREES. Trees - Introduction

Data Structures and Algorithms

CSCI Trees. Mark Redekopp David Kempe

The B-Tree. Yufei Tao. ITEE University of Queensland. INFS4205/7205, Uni of Queensland

Search Trees. COMPSCI 355 Fall 2016

Uses for Trees About Trees Binary Trees. Trees. Seth Long. January 31, 2010

What is a Multi-way tree?

Comp 335 File Structures. B - Trees

Introduction. for large input, even access time may be prohibitive we need data structures that exhibit times closer to O(log N) binary search tree

Sorted Arrays. Operation Access Search Selection Predecessor Successor Output (print) Insert Delete Extract-Min

Motivation for B-Trees

Algorithms. Deleting from Red-Black Trees B-Trees

Multi-way Search Trees! M-Way Search! M-Way Search Trees Representation!

Search Trees. The term refers to a family of implementations, that may have different properties. We will discuss:

2-3 Tree. Outline B-TREE. catch(...){ printf( "Assignment::SolveProblem() AAAA!"); } ADD SLIDES ON DISJOINT SETS

EE 368. Weeks 5 (Notes)

CS F-11 B-Trees 1

B-Trees. Introduction. Definitions

2-3 and Trees. COL 106 Shweta Agrawal, Amit Kumar, Dr. Ilyas Cicekli

Chapter 20: Binary Trees

Binary Trees

9/29/2016. Chapter 4 Trees. Introduction. Terminology. Terminology. Terminology. Terminology

File Organization. Kuan-Yu Chen ( 陳冠宇 ) TR-212, NTUST

BINARY SEARCH TREES cs2420 Introduction to Algorithms and Data Structures Spring 2015

B-Trees & its Variants

C SCI 335 Software Analysis & Design III Lecture Notes Prof. Stewart Weiss Chapter 4: B Trees

CS350: Data Structures B-Trees

Properties of red-black trees

8. Binary Search Tree

CS 310 B-trees, Page 1. Motives. Large-scale databases are stored in disks/hard drives.

B-Trees. Disk Storage. What is a multiway tree? What is a B-tree? Why B-trees? Insertion in a B-tree. Deletion in a B-tree

Algorithms. AVL Tree

13.4 Deletion in red-black trees

Balanced Search Trees

Chapter 12 Advanced Data Structures

Binary Search Tree (3A) Young Won Lim 6/2/18

13.4 Deletion in red-black trees

An AVL tree with N nodes is an excellent data. The Big-Oh analysis shows that most operations finish within O(log N) time

Physical Level of Databases: B+-Trees

Linked Structures Songs, Games, Movies Part III. Fall 2013 Carola Wenk

Material You Need to Know

CS 350 : Data Structures B-Trees

Trees. Eric McCreath

Background: disk access vs. main memory access (1/2)

M-ary Search Tree. B-Trees. B-Trees. Solution: B-Trees. B-Tree: Example. B-Tree Properties. Maximum branching factor of M Complete tree has height =

Search Trees. Undirected graph Directed graph Tree Binary search tree

Lecture 6: Analysis of Algorithms (CS )

Balanced Binary Search Trees. Victor Gao

Binary Trees. Examples:

(2,4) Trees Goodrich, Tamassia. (2,4) Trees 1

Binary Search Tree (2A) Young Won Lim 5/17/18

Red-Black Trees. Based on materials by Dennis Frey, Yun Peng, Jian Chen, and Daniel Hood

A red-black tree is a balanced binary search tree with the following properties:

CS127: B-Trees. B-Trees

Search Trees - 1 Venkatanatha Sarma Y

Binary Trees, Binary Search Trees

Data Structure - Advanced Topics in Tree -

M-ary Search Tree. B-Trees. Solution: B-Trees. B-Tree: Example. B-Tree Properties. B-Trees (4.7 in Weiss)

Associate Professor Dr. Raed Ibraheem Hamed

Hash Functions. Kuan-Yu Chen ( 陳冠宇 ) TR-212, NTUST

Trees. Truong Tuan Anh CSE-HCMUT

Computational Optimization ISE 407. Lecture 16. Dr. Ted Ralphs

Trees can be used to store entire records from a database, serving as an in-memory representation of the collection of records in a file.

Programming II (CS300)

Section 5.5. Left subtree The left subtree of a vertex V on a binary tree is the graph formed by the left child L of V, the descendents

Binary Search Tree (3A) Young Won Lim 6/6/18

PART IV. Given 2 sorted arrays, What is the time complexity of merging them together?

Multi-Way Search Tree

CSCI2100B Data Structures Heaps

B-Trees and External Memory

Binary Search Tree (3A) Young Won Lim 6/4/18

CIS265/ Trees Red-Black Trees. Some of the following material is from:

Tree-Structured Indexes

Binary Search Trees. Analysis of Algorithms

Trees can be used to store entire records from a database, serving as an in-memory representation of the collection of records in a file.

B-Trees and External Memory

Lecture: Analysis of Algorithms (CS )

Overview of Presentation. Heapsort. Heap Properties. What is Heap? Building a Heap. Two Basic Procedure on Heap

Balanced Search Trees. CS 3110 Fall 2010

CS301 - Data Structures Glossary By

Advanced Set Representation Methods

Lecture 11: Multiway and (2,4) Trees. Courtesy to Goodrich, Tamassia and Olga Veksler

Multiway Search Trees. Multiway-Search Trees (cont d)

Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology

Trees (Part 1, Theoretical) CSE 2320 Algorithms and Data Structures University of Texas at Arlington

Outline. Computer Science 331. Insertion: An Example. A Recursive Insertion Algorithm. Binary Search Trees Insertion and Deletion.

Trees. Q: Why study trees? A: Many advance ADTs are implemented using tree-based data structures.

B Tree. Also, every non leaf node must have at least two successors and all leaf nodes must be at the same level.

Laboratory Module Trees

Transcription:

Multi-way Search Trees Kuan-Yu Chen ( 陳冠宇 ) 2018/10/24 @ TR-212, NTUST

Review Red-Black Trees Splay Trees Huffman Trees 2

Multi-way Search Trees. Every node in a binary search tree contains one value and two pointers, left and right, which point to the node s left and right sub-trees An M-way search tree has MM 1 values per node and MM subtrees MM is called the degree of the tree If MM = 2, each node in the M-way search tree has one value and two sub-trees Binary Search Tree! 3

For a M-way search tree Multi-way Search Trees.. All the key values are stored in ascending order 3-way search tree It is not compulsory that every node has exactly M 1 values and M subtrees The node can have anywhere from 1 to M 1 values The number of sub-trees can vary from 0 (leaf node) to ii + 1 ii is the number of key values in the node M is a fixed upper bound, ii + 1 MM 4

B Trees. A B tree is a specialized M-way tree developed by Rudolf Bayer and Ed McCreight in 1970 A B tree of order mm can have a maximum of mm 1 keys and mm pointers to its sub-trees A B tree of order mm is a tree with all the properties of an M- way search tree and has additional properties Every node in the B tree has at most (maximum) mm children Every node in the B tree except the root node and leaf nodes has at least (minimum) mm children 2 Degree=4, at least 2 children, at least 1 key Degree=5, at least 3 children, at least 2 key The root node has at least two children All leaf nodes are at the same level 5

B Trees.. A B tree of order 4 While performing insertion and deletion operations in a B tree, the number of child nodes may change The internal nodes may be joined or split to maintain a minimum number of children 6

Searching in a B Tree. To search for 59 The root node has a value 45 which is less than 59 Go to right sub-tree The right sub-tree of the root node has two key values, 49 and 63 Since 49 < 59 < 63, traverse the right sub-tree of 49, or the left subtree of 63 This sub-tree has three values, 54, 59, and 61 Terminal 7

Searching in a B Tree.. To search for 9 Traverse the left sub-tree of the root node The left sub-tree has two key values, 29 and 32 Traverse the left sub-tree of 29 The sub-tree has two key values, 18 and 27 There is no left sub-tree of 18 The value 9 is not stored in the tree 8

Inserting a New Element In a B tree, all insertions are done at the leaf node level 1. Search the B tree to find the leaf node where the new key value should be inserted 2. If the leaf node is not full Insert the new element in the node keeping the node s elements ordered 3. If the leaf node is full Insert the new value in order into the existing set of keys Split the node at its median into two nodes The split nodes are half full Push the median element up to its parent s node If the parent s node is already full Split the parent node by the same steps 9

Example. Given a B tree of order 5, please insert 8, 9, 39, and 4 into it 10

Example.. Given a B tree of order 5, please insert 8, 9, 39, and 4 into it 11

Example... Given a B tree of order 5, please insert 8, 9, 39, and 4 into it 12

Deleting a New Element. There are two cases of deletion A leaf node has to be deleted An internal node has to be deleted Promote the successor or predecessor of the key in the leaf node to be deleted to occupy the position of the deleted key The processing will be done as if a value from the leaf node has been deleted 13

Deleting a New Element.. A leaf node has to be deleted Locate the leaf node which has to be deleted If the leaf node contains more than the minimum number of key values, then delete the value If the leaf node does not contain the minimum number elements, then fill the node by taking an element either from the left or from the right sibling If the left sibling has more than the minimum number of key values push its largest key into its parent s node pull down the suitable (intervening) element from the parent node to replace the deleted element If the right sibling has more than the minimum number of key values If both left and right siblings contain only the minimum number of elements 14

Deleting a New Element... If the left sibling has more than the minimum number of key values If the right sibling has more than the minimum number of key values push its smallest key into its parent s node pull down the suitable (intervening) element from the parent node to replace the deleted element If both left and right siblings contain only the minimum number of elements create a new leaf node by combining the two leaf nodes (target+left or target+right) and the intervening element of the parent node if the parent node contains less than the minimum number of keys in the node propagate the process upwards, thereby reducing the height of the B tree 15

Example 1. Given a B tree of order 5, please delete values 93, 201, 180, and 72 16

Example 1.. Given a B tree of order 5, please delete values 93, 201, 180, and 72 17

Example 1 Given a B tree of order 5, please delete values 93, 201, 180, and 72 18

Example 1 Given a B tree of order 5, please delete values 93, 201, 180, and 72 19

Example 1. Given a B tree of order 5, please delete values 93, 201, 180, and 72 20

Example 1. Given a B tree of order 5, please delete values 93, 201, 180, and 72 21

Example 1. Given a B tree of order 5, please delete values 93, 201, 180, and 72 63 New Node: 36,45,63,79 22

Example 1. Given a B tree of order 5, please delete values 93, 201, 180, and 72 108 New Node: 81,108,117,256 New Node: 36,45,63,79 23

Example 2. Given a B tree of order 3, please insert 121, 87 and then delete 36, 109 24

Example 2.. Given a B tree of order 3, please insert 121, 87 and then delete 36, 109 25

Example 2... Given a B tree of order 3, please insert 121, 87 and then delete 36, 109 26

Example 2... Given a B tree of order 3, please insert 121, 87 and then delete 36, 109 27

Example 2... Given a B tree of order 3, please insert 121, 87 and then delete 36, 109 117 New Node: 117, 121 28

Example 2... Given a B tree of order 3, please insert 121, 87 and then delete 36, 109 108 New Node: 87, 108 117 New Node: 117, 121 29

Example 3. Given a B tree of order 5, please delete 58, 65 30

Example 3. Given a B tree of order 5, please delete 58, 65 57 31

Example 3. Given a B tree of order 5, please delete 58, 65 55 57 New Node: 38, 40, 55, 56 32

Example 3. Given a B tree of order 5, please delete 58, 65 New Node: 5, 15, 35, 57 35 55 57 New Node: 38, 40, 55, 56 33

Example 3.. Given a B tree of order 5, please delete 58, 65 34

Example 3.. Given a B tree of order 5, please delete 58, 65 68 New Node: 63, 68, 70, 77 35

Example 3.. Given a B tree of order 5, please delete 58, 65 57 62 68 New Node: 63, 68, 70, 77 36

Check the Demo! https://www.cs.usfca.edu/~galles/visualization/btree.html 37

Questions? kychen@mail.ntust.edu.tw 38