Lecture 16 Multiway Search Trees

Slides:



Advertisements
Similar presentations
© 2004 Goodrich, Tamassia Binary Search Trees   
Advertisements

© 2004 Goodrich, Tamassia (2,4) Trees
Indexing (cont.). Insertion in a B+ Tree Another B+ Tree
CSC 213 Lecture 8: (2,4) Trees. Review of Last Lecture Binary Search Tree – plain and tall No balancing, no splaying, no speed AVL Tree – liberté, égalité,
© 2004 Goodrich, Tamassia Trees
(2,4) Trees1 What are they? –They are search Trees (but not binary search trees) –They are also known as 2-4, trees.
CS422 Principles of Database Systems Indexes
Balanced Search Trees 2-3 Trees AVL Trees Red-Black Trees
COMP261 Lecture 23 B Trees.
Binary Search Trees < > = © 2010 Goodrich, Tamassia
Binary Search Trees < > =
Lecture 15 Nov 3, 2013 Height-balanced BST Recall:
AA Trees.
AVL Trees 5/17/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M.
B/B+ Trees 4.7.
Multiway Search Trees Data may not fit into main memory
B-Trees B-Trees.
Binary Search Trees < > =
AVL Trees 6/25/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M.
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.
Lecture 15 AVL Trees Slides modified from © 2010 Goodrich, Tamassia & by Prof. Naveen Garg’s Lectures.
Red Black Trees
CSIT 402 Data Structures II
Lecture 17 Red-Black Trees
Chapter 10 Search Trees 10.1 Binary Search Trees Search Trees
Chapter 11: Multiway Search Trees
Binary Search Tree Chapter 10.
Chapter 10.1 Binary Search Trees
Heaps © 2010 Goodrich, Tamassia Heaps Heaps
Dynamic Dictionaries Primary Operations: Additional operations:
AVL Trees 11/10/2018 AVL Trees v z AVL Trees.
AVL Trees 4/29/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H.
(2,4) Trees (2,4) Trees 1 (2,4) Trees (2,4) Trees
Chapter 6 Transform and Conquer.
Wednesday, April 18, 2018 Announcements… For Today…
Topics covered (since exam 1):
Lecture 26 Multiway Search Trees Chapter 11 of textbook
Binary Search Trees < > = © 2010 Goodrich, Tamassia
B-Trees (continued) Analysis of worst-case and average number of disk accesses for an insert. Delete and analysis. Structure for B-tree node.
Balanced-Trees This presentation shows you the potential problem of unbalanced tree and show two way to fix it This lecture introduces heaps, which are.
(2,4) Trees /26/2018 3:48 PM (2,4) Trees (2,4) Trees
B-Trees CSE 373 Data Structures CSE AU B-Trees.
v z Chapter 10 AVL Trees Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich,
Priority Queues (Chapter 6.6):
Balanced-Trees This presentation shows you the potential problem of unbalanced tree and show two way to fix it This lecture introduces heaps, which are.
(2,4) Trees (2,4) Trees (2,4) Trees.
Binary Search Trees < > =
Algorithms and Data Structures Lecture VIII
Mainly from Chapter 7 Adam Drozdek
Topics covered (since exam 1, excluding PQ):
(2,4) Trees 2/15/2019 (2,4) Trees (2,4) Trees.
B-TREE ________________________________________________________
Binary Search Trees < > =
(2,4) Trees /24/2019 7:30 PM (2,4) Trees (2,4) Trees
AVL Trees 2/23/2019 AVL Trees v z AVL 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,4) Trees (2,4) Trees (2,4) Trees.
Binary Search Trees < > =
CSE 373: Data Structures and Algorithms
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.
(2,4) Trees /6/ :26 AM (2,4) Trees (2,4) Trees
CSE 373 Data Structures and Algorithms
CSE 373: Data Structures and Algorithms
Priority Queues (Chapter 6):
B-Trees.
CSE 373 Data Structures Lecture 8
Red Black Trees.
1 Lecture 13 CS2013.
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.
CS210- Lecture 20 July 19, 2005 Agenda Multiway Search Trees 2-4 Trees
Presentation transcript:

Lecture 16 Multiway Search Trees Slides modified from © 2010 Goodrich, Tamassia & by Prof. Naveen Garg’s Lectures

Ordered Maps So far List/Array BST AVL Tree

Lets try multiple children… 30 25 40 50 75

Multiple keys at each node! 30 50 25 40 75

How many keys do we need at a node to have d-way search tree?

Confusion Points 1. nodes 2. keys 3. children

Multiway search tree with degree d! internal nodes have at least 2 children and at max d children each node stores upto d-1 items

In-order traversal of multiway tree 30 50 25 29 40 75 80 14 20 26 27

Search 12

Search 24

What is the time complexity of search in a d-way search tree?

O(h*log d)

2-4 Tree a node can have 2 to 4 children all leaf nodes are at the same level

Search complexity? O(h)

Min & Max height (h)?

Minimum number of entries? n≥2h+1-1 h≤log2(n+1)-1

Maximum number of entries? n≤4h+1-1 h≥log4(n+1)-1

log4(n+1)-1 ≤ h ≤ log2(n+1)-1 1/2log2(n+1) ≤ h+1 ≤ log2(n+1) O(log n) 2-4 Tree Height log4(n+1)-1 ≤ h ≤ log2(n+1)-1 1/2log2(n+1) ≤ h+1 ≤ log2(n+1) O(log n)

Insert

Case1: Node has empty space 21 23 40 29 7 13 22 32 3 8 10 18 25 35 1 2 4 5 6 9 11 12 14 15 20 24 26 28 30 33 37 39

Case2: node is already full split the node 29 7 13 22 32 3 8 10 18 25 35 1 2 4 5 6 9 11 12 14 15 20 21 23 24 26 28 30 33 37 39 40

Promote one key to the parent! 7 13 22 32 3 8 10 18 25 35 1 2 4 5 6 9 11 12 14 15 20 21 23 24 33 37 39 40 26 28 29 30

Promote one key to the parent! Split the parent! 13 22 32 3 8 10 18 25 28 35 1 2 9 11 12 14 15 20 21 23 24 33 37 39 40 4 5 6 7 26 29 30

Eventually, we may have to create a new root! 5 13 22 32 3 8 10 18 25 28 35 1 2 9 11 12 14 15 20 21 23 24 33 37 39 40 4 6 7 26 29 30

Complexity of insert? o(log n) O(log n) to find the node O(log n) node splits in the worst Node split takes constant time o(log n)

Delete

Claim: We always delete key in the leaf node! 13 5 22 3 8 10 18 25 28 1 2 9 11 12 14 15 20 23 24 4 6 7 26 29 30

Case 1: leaf node has at least 2 keys Delete 21 13 5 22 3 8 10 18 25 28 1 2 9 11 12 14 15 20 21 23 24 4 6 7 26 29 30

Case 1: leaf node has at least 2 keys Delete 25 13 5 22 3 8 10 18 25 28 1 2 9 11 12 14 15 20 23 24 4 6 7 26 29 30

Case 2: leaf node has only 1 key Delete 20 borrow from sibling 13 5 22 3 8 10 18 24 28 1 2 9 11 12 14 15 20 23 4 6 7 26 29 30

What if sibling has only 1 key? Delete 23 Merge siblings 13 5 22 3 8 10 15 24 28 1 2 9 11 12 14 18 23 4 6 7 26 29 30

What if the parent has only 1 key? Delete 18 Cascaded merge 13 5 22 3 8 10 15 28 1 2 9 11 12 14 18 4 6 7 29 30 24 26

2-4 Trees The height of a (2,4) tree is O(log n). Search, insertion and deletion each take O(log n) . Pretty fundamental to the ideas of advanced trees such as Red-Black trees.