Wednesday, April 18, 2018 Announcements… For Today…

Slides:



Advertisements
Similar presentations
B+-Trees (PART 1) What is a B+ tree? Why B+ trees? Searching a B+ tree
Advertisements

AA Trees another alternative to AVL trees. Balanced Binary Search Trees A Binary Search Tree (BST) of N nodes is balanced if height is in O(log N) A balanced.
CSE332: Data Abstractions Lecture 9: B Trees Dan Grossman Spring 2010.
B-Trees. Motivation for B-Trees Index structures for large datasets cannot be stored in main memory Storing it on disk requires different approach to.
B-Trees Disk Storage What is a multiway tree? What is a B-tree?
Self-Balancing Search Trees Chapter 11. Chapter 11: Self-Balancing Search Trees2 Chapter Objectives To understand the impact that balance has on the performance.
Fall 2007CS 2251 Self-Balancing Search Trees Chapter 9.
1 B-Trees Disk Storage What is a multiway tree? What is a B-tree? Why B-trees? Comparing B-trees and AVL-trees Searching a B-tree Insertion in a B-tree.
Self-Balancing Search Trees Chapter 11. Chapter Objectives  To understand the impact that balance has on the performance of binary search trees  To.
B-Trees and B+-Trees Disk Storage What is a multiway tree?
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.
B + -Trees COMP171 Fall AVL Trees / Slide 2 Dictionary for Secondary storage * The AVL tree is an excellent dictionary structure when the entire.
1 B-Trees Section AVL (Adelson-Velskii and Landis) Trees AVL tree is binary search tree with balance condition –To ensure depth of the tree is.
B-trees (Balanced Trees) A B-tree is a special kind of tree, similar to a binary tree. However, It is not a binary search tree. It is not a binary tree.
Balanced Search Trees Fundamental Data Structures and Algorithms Margaret Reid-Miller 3 February 2005.
2-3 Tree. Slide 2 Outline  Balanced Search Trees 2-3 Trees Trees.
Starting at Binary Trees
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.
Priority Queues and Heaps. October 2004John Edgar2  A queue should implement at least the first two of these operations:  insert – insert item at the.
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.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
CompSci Memory Model  For this course: Assume Uniform Access Time  All elements in an array accessible with same time cost  Reality is somewhat.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
B-Trees Katherine Gurdziel 252a-ba. Outline What are b-trees? How does the algorithm work? –Insertion –Deletion Complexity What are b-trees used for?
Priority Queues and Heaps. John Edgar  Define the ADT priority queue  Define the partially ordered property  Define a heap  Implement a heap using.
Balanced Search Trees 2-3 Trees AVL Trees Red-Black Trees
COMP261 Lecture 23 B Trees.
Data Structures and Design in Java © Rick Mercer
TCSS 342, Winter 2006 Lecture Notes
AA Trees.
CSCE 3110 Data Structures & Algorithm Analysis
CSCE 3110 Data Structures & Algorithm Analysis
B-Trees B-Trees.
Data Structures – LECTURE Balanced trees
B/B+ Trees 4.7.
Multiway Search Trees Data may not fit into main memory
Search Trees.
B-Trees B-Trees.
B-Trees B-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.
Red Black Trees
Week 6 - Wednesday CS221.
CSCI Trees and Red/Black Trees
Red-Black Trees v z Red-Black Trees 1 Red-Black Trees
Week 11 - Friday CS221.
B-Trees Disk Storage What is a multiway tree? What is a B-tree?
Monday, April 16, 2018 Announcements… For Today…
original list {67, 33,49, 21, 25, 94} pass { } {67 94}
Self-Balancing Search Trees
Lecture 26 Multiway Search Trees Chapter 11 of textbook
Friday, April 13, 2018 Announcements… For Today…
B-Trees (continued) Analysis of worst-case and average number of disk accesses for an insert. Delete and analysis. Structure for B-tree node.
Red-Black Trees v z Red-Black Trees 1 Red-Black Trees
B+ Trees What are B+ Trees used for What is a B Tree What is a B+ Tree
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.
Search Sorted Array: Binary Search Linked List: Linear Search
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.
B-Trees Disk Storage What is a multiway tree? What is a B-tree?
CSIT 402 Data Structures II With thanks to TK Prasad
B-Trees Disk Storage What is a multiway tree? What is a B-tree?
Self-Balancing 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.
Richard Anderson Spring 2016
Mark Redekopp David Kempe
B-Trees.
B-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.
Self-Balancing Search Trees
Self-Balancing Search Trees
Presentation transcript:

Wednesday, April 18, 2018 Announcements… For Today… Self-Balancing Search Trees Announcements… Bonus AVL Lab and Quicksort Reviews due Friday Final Exam Richard's Building April 20-25th. Exam review. Direct emails to cs235ta@cs.byu.edu (w/netid) For Today… 11.3 Trees

Attendance Quiz #41 Self-Balancing Search Trees

An algorithm completes 32 iterations in 5 ms An algorithm completes 32 iterations in 5 ms. Fill in the following times: O(1) O(log n) O(n) O(n2) O(n3) O(2n) O(n!) 32 5 33 64 128

Which STL Container to Use?

Which STL Container to Use? Self-Balancing Search Trees

11.4, pgs. 656-672 11.4 2-3 Trees Searching a 2-3 Tree Inserting an Item into a 2-3 Tree Analysis of 2-3 Trees and Comparison with Balanced Binary Trees Removal from a 2-3 Tree 11.4, pgs. 656-672

2-3 Trees Self-Balancing Search Trees A 2-3 tree consists of nodes designated as either 2-nodes or 3- nodes A 2-node is the same as a binary search tree node: it contains a data field and references to two child nodes one child node contains data less than the node's data value the other child contains data greater than the node's data value A 3-node contains two data fields, ordered so that first is less than the second, and references to three children One child contains data values less than the first data field One child contains data values between the two data fields One child contains data values greater than the second data field All the leaves of a 2-3 tree are at the lowest level

2-3 Trees Self-Balancing Search Trees

Searching a 2-3 Tree Self-Balancing Search Trees Searching a 2-3 tree is very similar to searching a binary search tree. if the local root is NULL Return NULL; the item is not in the tree. else if this is a 2-node if the item is equal to the data1 field Return the data1 field. else if the item is less than the data1 field Recursively search the left subtree. else Recursively search the right subtree. else // This is a 3-node else if the item is equal to the data2 field Return the data2 field. else if the item is less than the data2 field Recursively search the middle subtree.

Searching a 2-3 Tree To search for 13 Self-Balancing Search Trees 7 3 11, 15 1 5 9 13 17, 19

Searching a 2-3 Tree To search for 13 Self-Balancing Search Trees Compare 13 and 7 7 3 11, 15 1 5 9 13 17, 19

Searching a 2-3 Tree To search for 13 Self-Balancing Search Trees 13 is greater than 7 7 3 11, 15 1 5 9 13 17, 19

Searching a 2-3 Tree To search for 13 Self-Balancing Search Trees 7 Compare 13 with 11 and 15 3 11, 15 1 5 9 13 17, 19

Searching a 2-3 Tree To search for 13 Self-Balancing Search Trees 7 13 is in between 11 and 15 11 < 13 < 15 3 11, 15 1 5 9 13 17, 19

Searching a 2-3 Tree To search for 13 Self-Balancing Search Trees 7 3 11, 15 1 5 9 13 17, 19 13 is in the middle child

Inserting an Item into a 2-3 Tree Self-Balancing Search Trees A 2-3 tree maintains balance by being built from the bottom up, not the top down Instead of hanging a new node onto a leaf, we insert the new node into a leaf

Inserting an Item into a 2-3 Tree Self-Balancing Search Trees Insert 15 7 3 11

Inserting an Item into a 2-3 Tree Self-Balancing Search Trees Insert 15 7 3 11 Because this node is a 2-node, we insert directly into the node creating a 3-node

Inserting an Item into a 2-3 Tree Self-Balancing Search Trees Insert 15 7 3 11, 15

Inserting an Item into a 2-3 Tree Self-Balancing Search Trees Insert 17 7 3 11, 15

Inserting an Item into a 2-3 Tree Self-Balancing Search Trees Insert 17 7 3 11, 15 Because we insert into leaves, 17 is virtually inserted into this node

Inserting an Item into a 2-3 Tree Self-Balancing Search Trees Insert 17 7 3 11, 15, 17 Because a node can't store three values, the middle value propagates up to the 2-node parent and this leaf node splits into two new 2-nodes

Inserting an Item into a 2-3 Tree Self-Balancing Search Trees Insert 17 7, 15 3 11 17

Inserting an Item into a 2-3 Tree Self-Balancing Search Trees Insert 5, 10, 20 7, 15 3 11 17

Inserting an Item into a 2-3 Tree Self-Balancing Search Trees Insert 5, 10, 20 7, 15 3, 5 11 17

Inserting an Item into a 2-3 Tree Self-Balancing Search Trees Insert 5, 10, 20 7, 15 3, 5 10, 11 17

Inserting an Item into a 2-3 Tree Self-Balancing Search Trees Insert 5, 10, 20 7, 15 3, 5 10, 11 17, 20

Inserting an Item into a 2-3 Tree Self-Balancing Search Trees Insert 13 7, 15 3, 5 10, 11 17, 20

Inserting an Item into a 2-3 Tree Self-Balancing Search Trees Insert 13 7, 15 3, 5 10, 11, 13 17, 20

Inserting an Item into a 2-3 Tree Self-Balancing Search Trees Insert 13 7, 15 3, 5 10, 11, 13 17, 20 Since a node with three values is a virtual node, move the middle value up and split the remaining values into two nodes

Inserting an Item into a 2-3 Tree Self-Balancing Search Trees Insert 13 7, 11, 15 3, 5 10 13 17, 20 Repeat

Inserting an Item into a 2-3 Tree Self-Balancing Search Trees 11 Insert 13 7, 15 3, 5 10 13 17, 20 Move the middle value up

Inserting an Item into a 2-3 Tree Self-Balancing Search Trees 11 Insert 13 7, 15 3, 5 10 13 17, 20 Split the remaining values into two nodes

Inserting an Item into a 2-3 Tree Self-Balancing Search Trees 11 Insert 13 7 15 3, 5 10 13 17, 20 Split the remaining values into two nodes

“The quick brown fox jumps over the lazy dog” Self-Balancing Search Trees “The quick brown fox jumps over the lazy dog”

“The quick brown fox jumps over the lazy dog” Insertion Example Self-Balancing Search Trees “The quick brown fox jumps over the lazy dog” The

“The quick brown fox jumps over the lazy dog” Insertion Example Self-Balancing Search Trees “The quick brown fox jumps over the lazy dog” The, quick

“The quick brown fox jumps over the lazy dog” Insertion Example Self-Balancing Search Trees “The quick brown fox jumps over the lazy dog” The, brown, quick

“The quick brown fox jumps over the lazy dog” Insertion Example Self-Balancing Search Trees “The quick brown fox jumps over the lazy dog” brown The quick

“The quick brown fox jumps over the lazy dog” Insertion Example Self-Balancing Search Trees “The quick brown fox jumps over the lazy dog” brown The fox, quick

“The quick brown fox jumps over the lazy dog” Insertion Example Self-Balancing Search Trees “The quick brown fox jumps over the lazy dog” brown The fox, jumps, quick

“The quick brown fox jumps over the lazy dog” Insertion Example Self-Balancing Search Trees “The quick brown fox jumps over the lazy dog” The brown, jumps fox quick

“The quick brown fox jumps over the lazy dog” Insertion Example Self-Balancing Search Trees “The quick brown fox jumps over the lazy dog” The brown, jumps fox over, quick

“The quick brown fox jumps over the lazy dog” Insertion Example Self-Balancing Search Trees “The quick brown fox jumps over the lazy dog” The brown, jumps fox over, quick, the

“The quick brown fox jumps over the lazy dog” Insertion Example Self-Balancing Search Trees “The quick brown fox jumps over the lazy dog” brown, jumps, quick The fox over the

“The quick brown fox jumps over the lazy dog” Insertion Example Self-Balancing Search Trees “The quick brown fox jumps over the lazy dog” jumps brown quick The fox over the

“The quick brown fox jumps over the lazy dog” Insertion Example Self-Balancing Search Trees “The quick brown fox jumps over the lazy dog” jumps brown quick The fox lazy, over the

“The quick brown fox jumps over the lazy dog” Insertion Example Self-Balancing Search Trees “The quick brown fox jumps over the lazy dog” jumps brown quick The dog, fox lazy, over the

2-3 Trees vs. Balanced Binary Trees Self-Balancing Search Trees 2-3 trees do not require the rotations needed for AVL and Red- Black trees. The number of items that a 2-3 tree of height h can hold is between 2h -1 (all 2 nodes) and 3h – 1 (all 3-nodes). Therefore, the height of a 2-3 tree is between log3 n and log2 n. The search time is O(log n) -- logarithms are all related by a constant factor, and constant factors are ignored in big-O notation.

11.4-5, pgs. 656-672 11.5 2-3-4 and B-Trees 2-3-4 Trees Implementation of the Two_Three_Four_Tree Class Relating 2-3-4 Trees to Red-Black Trees B-Trees 11.4-5, pgs. 656-672

B-Tree A B-Tree is a "fat" self-balancing search tree. Self-Balancing Search Trees A B-Tree is a "fat" self-balancing search tree. Self-balancing search trees (like AVL and Red Black Trees), assume that everything is in main memory. B-Trees work with huge amounts of data that cannot fit in main memory. Since disk access time is very high compared to main memory access time, B-Trees make accesses more productive. Using B-Trees reduces the number of disk accesses by putting maximum possible keys in a B-Tree node. Most of the tree operations (search, insert, delete, max, min, ..etc ) require O(h) disk accesses where h is height of the tree. Height of B-Trees is kept low such that the total disk accesses for most operations is significantly reduced. Generally, a B-Tree node size is kept equal to the disk block size.

B-Trees and 2-3-4 Trees Self-Balancing Search Trees The 2-3 tree was the inspiration for the more general B-tree which allows up to n children per node, where n may be a very large number. 2-3-4 trees are a special case of the B-tree where order is fixed at 4. A node in a 2-3-4 tree is called a 4-node. A 4-node has space for three data items and four children.

Properties of B-Tree All leaves are at same level. Self-Balancing Search Trees All leaves are at same level. A B-Tree is defined by the term minimum degree ‘t’. The value of t depends upon disk block size. Every node except root must contain at least t-1 keys. Root may contain minimum 1 key. All nodes (including root) may contain at most 2t – 1 keys. Number of children of a node is equal to the number of keys in it plus 1. All keys of a node are sorted in increasing order. The child between two keys k1 and k2 contains all keys in range from k1 and k2. B-Tree grows and shrinks from root which is unlike Binary Search Tree. Binary Search Trees grow downward and also shrink from downward. Like other balanced Binary Search Trees, time complexity to search, insert and delete is O(Log n).