Multi-Way Search Tree

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

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

Binary Trees, Binary Search Trees

TREES. Trees - Introduction

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

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

CS350: Data Structures Binary Search Trees

CS 350 : Data Structures Binary Search Trees

Lec 17 April 8. Topics: binary Trees expression trees. (Chapter 5 of text)

Search Trees - 1 Venkatanatha Sarma Y

Binary Search Trees > = 2014 Goodrich, Tamassia, Goldwasser. Binary Search Trees 1

Chapter 20: Binary Trees

Programming II (CS300)

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

CSCI-401 Examlet #5. Name: Class: Date: True/False Indicate whether the sentence or statement is true or false.

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

Operations on Heap Tree The major operations required to be performed on a heap tree are Insertion, Deletion, and Merging.

Data Structures and Algorithms for Engineers

March 20/2003 Jayakanth Srinivasan,

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

B-Trees and External Memory

Binary Tree. Preview. Binary Tree. Binary Tree. Binary Search Tree 10/2/2017. Binary Tree

CS24 Week 8 Lecture 1

B-Trees and External Memory

Self-Balancing Search Trees. Chapter 11

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

Binary Trees

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

Balanced Search Trees. CS 3110 Fall 2010

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

a graph is a data structure made up of nodes in graph theory the links are normally called edges

A set of nodes (or vertices) with a single starting point

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example.

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

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

Search Trees (Ch. 9) > = Binary Search Trees 1

Augmenting Data Structures

Algorithms. AVL Tree

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

Trees. Truong Tuan Anh CSE-HCMUT

Some Search Structures. Balanced Search Trees. Binary Search Trees. A Binary Search Tree. Review Binary Search Trees

Principles of Computer Science

Partha Sarathi Mandal

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

We have the pointers reference the next node in an inorder traversal; called threads

Binary Trees. Examples:

BST Implementation. Data Structures. Lecture 4 Binary search trees (BST) Dr. Mahmoud Attia Sakr University of Ain Shams

Trees, Binary Trees, and Binary Search Trees

Binary Search Trees. See Section 11.1 of the text.

Tree traversals and binary trees

SCJ2013 Data Structure & Algorithms. Binary Search Tree. Nor Bahiah Hj Ahmad

Data Structures and Algorithms

Trees. CSE 373 Data Structures

Tree Structures. A hierarchical data structure whose point of entry is the root node

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

Trees. Courtesy to Goodrich, Tamassia and Olga Veksler

Friday Four Square! 4:15PM, Outside Gates

CS 231 Data Structures and Algorithms Fall Recursion and Binary Trees Lecture 21 October 24, Prof. Zadia Codabux

Presentation for use with the textbook Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015

Tree. A path is a connected sequence of edges. A tree topology is acyclic there is no loop.

Lecture 6: Analysis of Algorithms (CS )

Associate Professor Dr. Raed Ibraheem Hamed

Data Structures in Java

A Binary Search Tree Implementation

CMSC351 - Fall 2014, Homework #2

Laboratory Module Trees

Binary Trees: Practice Problems

Cpt S 122 Data Structures. Data Structures Trees

SFU CMPT Lecture: Week 9

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

Programming Languages and Techniques (CIS120)

Algorithms. Deleting from Red-Black Trees B-Trees

INF2220: algorithms and data structures Series 1

Dictionaries. Priority Queues

Title Description Participants Textbook

Why Use Binary Trees? Data Structures - Binary Trees 1. Trees (Contd.) Trees

CS350: Data Structures B-Trees

CHAPTER 10 AVL TREES. 3 8 z 4

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

Data Structures - Binary Trees 1

Search Trees. COMPSCI 355 Fall 2016

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

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

Balanced Search Trees

CS350: Data Structures Red-Black Trees

Data Structure: Search Trees 2. Instructor: Prof. Young-guk Ha Dept. of Computer Science & Engineering

Binary Search Trees. Nearest Neighbor Binary Search Trees Insertion Predecessor and Successor Deletion Algorithms on Trees.

CS350: Data Structures Tree Traversal

To find a value in a BST search from the root node:

Binary Trees. BSTs. For example: Jargon: Data Structures & Algorithms. root node. level: internal node. edge.

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

Binary Search Trees. Binary Search Trees. Nearest Neighbor. Nearest Neighbor

Advanced Java Concepts Unit 5: Trees. Notes and Exercises

Chapter 10: Search Trees

CS 171: Introduction to Computer Science II. Binary Search Trees

8. Binary Search Tree

Data Structure Lecture#10: Binary Trees (Chapter 5) U Kang Seoul National University

(D) There is a constant value n 0 1 such that B is faster than A for every input of size. n n 0.

Lecture 23: Binary Search Trees

Chapter 5. Binary Trees

Transcription:

Multi-Way Search Tree A multi-way search tree is an ordered tree such that Each internal node has at least two and at most d children and stores d -1 data items (k i, D i ) Rule: Number of children = 1 + number of data items in a node k 1 D 1 k 2 D 2... k d-1 D d-1 child 1 child 2 child child d d is the degree or order of the tree

Multi-Way Search Tree A multi-way search tree is an ordered tree such that Each internal node has at least two and at most d children and stores d -1 data items (k i, D i ) An internal node storing keys k 1 k 2 k d-1 has d children v 1 v 2 v d such that k 1 k 2... k d-1 < k 1 > k 1 < k 2 > k 2 < k > k d-2 < k d-1 > k d-1 (2,4) Trees 2

Multi-Way Search Tree A multi-way search tree is an ordered tree such that Each internal node has at least two and at most d children and stores d -1 data items (k i, D i ) An internal node storing keys k 1 k 2 k d-1 has d children v 1 v 2 v d such that By convenience we add sentinel keys k 0 = - and k d = k 0 = - k 1 k 2... k d-1 k d = < k 1 > k 1 < k 2 > k 2 < k > k d-2 < k d-1 > k d-1 (2,4) Trees

Multi-Way Search Tree A multi-way search tree is an ordered tree such that Each internal node has at least two and at most d children and stores d -1 data items (k i, D i ) An internal node storing keys k 1 k 2 k d-1 has d children v 1 v 2 v d such that By convenience we add sentinel keys k 0 = - and k d = The leaves store no items and serve as placeholders 11 24 2 6 8 15 27 2 0 (2,4) Trees 4

Multi-Way Search Tree 27 41 5 20 2 2 9 47 57 59 6 1 50 1 17 (2,4) Trees 5

Multi-Way Search Tree 27 41 5 15 2 2 9 47 57 59 6 1 50 1 17 Not a multiway search tree (2,4) Trees 6

Multi-Way Inorder Traversal We can extend the notion of inorder traversal from binary trees to multi-way search trees An inorder traversal of a multi-way search tree visits the keys in increasing order 11 24 2 6 8 15 27 2 0 Inorder traversal: 2, 6, 8, 11, 15, 24, 27, 0, 2 (2,4) Trees 7

Data Structures for Multi-Way Search Trees k 0 = - k 1 k 2... k d-1 k d = child 1 child 2 child child d node null D 1 D 2... D d-1 null data - k 1 k 2... k d-1 keys ch1 ch 2 ch ch d children 0 1 2 d-1 (2,4) Trees 8

Data Structures for Multi-Way Search Trees k 0 = - k 1 k 2... k d-1 k d = child 1 child 2 child child d null D 1 D 2... D d-1 null data - k 1 k 2... k d-1 keys ch1 ch 2 ch ch d children 0 1 2 d-1 Secondary data structures (2,4) Trees 9

Multi-Way Searching Similar to search in a binary search tree Example: search for 1 27 41 5 20 2 2 9 47 57 59 6 1 50 (2,4) Trees 10

Multi-Way Searching Similar to search in a binary search tree Example: search for 46 27 41 5 20 2 2 9 47 57 59 6 1 50 (2,4) Trees 11

Multi-Way Searching Algorithm get(r,k) In: Root r of a multiway search tree, key k Out: data for key k or null if k not in tree if r is a leaf then return null else { } Use binary search to find the index i such that r.keys[i] k < r.keys[i+1] if k = r.keys[i] then return r.data[i] else return get(r.child[i],k) (2,4) Trees 12

Multi-Way Searching Algorithm get(r,k) In: Root r of a multiway search tree, key k Out: data for key k or null if k not in tree if r is a leaf then return null else { } Use binary search to find the index i such that r.keys[i] k < r.keys[i+1] if k = r.keys[i] then return r.data[i] else return get(r,r.child[i]) c operations Ignoring recursive calls: c 1 log d + c 2 operations (2,4) Trees 1

Time Complexity of get Operation c1 + c2 log d c1 + c2 log d c1 + c2 log d... c f(n) = c + (c1 + c2 log d) height of tree is O(log d height of tree) (2,4) Trees 14

Smallest Operation c c c k s... c f(n) = c height of tree is O(height of tree) (2,4) Trees 15

Successor Operation 27 41 5 20 2 2 9 47 57 59 6 1 50 1 17 smallest value in subtree successor (27) (2,4) Trees 16

Successor Operation 27 41 5 20 2 2 9 47 57 59 6 1 50 1 17 successor (17) (2,4) Trees 17

Successor Operation 27 41 5 20 2 2 9 47 57 59 6 1 50 1 17 Time complexity: get + smallest: O(log d height), or get + travel up: O(log d height) so time complexity is O(log d height) (2,4) Trees 18

Put Operation 27 41 5 20 2 2 9 47 57 59 6 1 50 1 17 insert (51) Assume degree = 4 (2,4) Trees 19

Put Operation 27 41 5 20 2 2 9 47 51 57 59 6 1 50 1 17 Time Complexity: Find node to store new data: O(log d height) Add data to node: O(d) time complexity: O(d+log d height) (2,4) Trees 20

Remove Operation 27 41 5 20 2 2 9 47 57 59 6 1 50 1 17 remove(50) (2,4) Trees 21

Remove Operation 27 41 5 20 2 2 9 47 57 59 6 1 50 1 17 remove(50) (2,4) Trees 22

Remove Operation 27 41 5 20 2 2 9 47 57 59 6 1 1 17 remove(50) (2,4) Trees 2

Remove Operation 27 41 5 20 2 2 9 47 57 59 6 1 1 17 remove(27) (2,4) Trees 24

Remove Operation 1 41 5 20 2 2 9 47 57 59 6 1 17 remove(27) (2,4) Trees 25

Remove Operation 1 41 5 20 2 2 9 47 57 59 6 1 17 Time complexity: get + smallest + remove data + delete 2 nodes: O(d+log d height) (2,4) Trees 26