Different Tree Data Structures for Different Problems

Slides:



Advertisements
Similar presentations
B-Trees. Motivation When data is too large to fit in the main memory, then the number of disk accesses becomes important. A disk access is unbelievably.
Advertisements

COL 106 Shweta Agrawal and Amit Kumar
Comp 122, Spring 2004 Binary Search Trees. btrees - 2 Comp 122, Spring 2004 Binary Trees  Recursive definition 1.An empty tree is a binary tree 2.A node.
Augmenting Data Structures Advanced Algorithms & Data Structures Lecture Theme 07 – Part I Prof. Dr. Th. Ottmann Summer Semester 2006.
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
1 Lecture 8: Data structures for databases II Jose M. Peña
Binary Search Trees CIS 606 Spring Search trees Data structures that support many dynamic-set operations. – Can be used as both a dictionary and.
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.
Tirgul 6 B-Trees – Another kind of balanced trees Some notes regarding Home Work.
CPSC 231 B-Trees (D.H.)1 LEARNING OBJECTIVES Problems with simple indexing. Multilevel indexing: B-Tree. –B-Tree creation: insertion and deletion of nodes.
B-Trees Disk Storage What is a multiway tree? What is a B-tree?
CS 206 Introduction to Computer Science II 12 / 01 / 2008 Instructor: Michael Eckmann.
Techniques and Data Structures for Efficient Multimedia Similarity Search.
B + -Trees (Part 1). Motivation AVL tree with N nodes is an excellent data structure for searching, indexing, etc. –The Big-Oh analysis shows most operations.
Tirgul 6 B-Trees – Another kind of balanced trees Problem set 1 - some solutions.
B + -Trees (Part 1) COMP171. Slide 2 Main and secondary memories  Secondary storage device is much, much slower than the main RAM  Pages and blocks.
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.
Index Structures Parin Shah Id:-207. Topics Introduction Structure of B-tree Features of B-tree Applications of B-trees Insertion into B-tree Deletion.
Tirgul 6 B-Trees – Another kind of balanced trees.
CPSC 335 BTrees Dr. Marina Gavrilova Computer Science University of Calgary Canada.
Indexing. Goals: Store large files Support multiple search keys Support efficient insert, delete, and range queries.
IntroductionIntroduction  Definition of B-trees  Properties  Specialization  Examples  2-3 trees  Insertion of B-tree  Remove items from B-tree.
B-Tree. B-Trees a specialized multi-way tree designed especially for use on disk In a B-tree each node may contain a large number of keys. The number.
Binary Tree. Binary Trees – An Informal Definition A binary tree is a tree in which no node can have more than two children Each node has 0, 1, or 2 children.
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.
1 B Trees - Motivation Recall our discussion on AVL-trees –The maximum height of an AVL-tree with n-nodes is log 2 (n) since the branching factor (degree,
1 B-Trees & (a,b)-Trees CS 6310: Advanced Data Structures Western Michigan University Presented by: Lawrence Kalisz.
March 7 & 9, Csci 2111: Data and File Structures Week 8, Lectures 1 & 2 Multi-Level Indexing and B-Trees.
Tree (new ADT) Terminology:  A tree is a collection of elements (nodes)  Each node may have 0 or more successors (called children)  How many does a.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Announcements Exam Friday. More Physical Storage Lecture 10.
COSC 2007 Data Structures II Chapter 15 External Methods.
B + -Trees. Motivation An AVL tree with N nodes is an excellent data structure for searching, indexing, etc. The Big-Oh analysis shows that most operations.
Binary SearchTrees [CLRS] – Chap 12. What is a binary tree ? A binary tree is a linked data structure in which each node is an object that contains following.
AVL Tree Definition: Theorem (Adel'son-Vel'skii and Landis 1962):
Starting at Binary Trees
Comp 335 File Structures B - Trees. Introduction Simple indexes provided a way to directly access a record in an entry sequenced file thereby decreasing.
Outline Binary Trees Binary Search Tree Treaps. Binary Trees The empty set (null) is a binary tree A single node is a binary tree A node has a left child.
MA/CSSE 473 Day 28 Dynamic Programming Binomial Coefficients Warshall's algorithm Student questions?
1 Tree Indexing (1) Linear index is poor for insertion/deletion. Tree index can efficiently support all desired operations: –Insert/delete –Multiple search.
AVL Trees. AVL Node Structure The AVL node structure follows the same structure as the binary search tree, with the addition of a term to store the.
Indexing and hashing Azita Keshmiri CS 157B. Basic concept An index for a file in a database system works the same way as the index in text book. For.
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.
B-trees Eduardo Laber David Sotelo. What are B-trees? Balanced search trees designed for secondary storage devices Similar to AVL-trees but better at.
Chapter 7 Trees_Part3 1 SEARCH TREE. Search Trees 2  Two standard search trees:  Binary Search Trees (non-balanced) All items in left sub-tree are less.
Data Structures and Algorithms (AT70.02) Comp. Sc. and Inf. Mgmt. Asian Institute of Technology Instructor: Prof. Sumanta Guha Slide Sources: CLRS “Intro.
1 Multi-Level Indexing and B-Trees. 2 Statement of the Problem When indexes grow too large they have to be stored on secondary storage. However, there.
Data Structures – Week #6 Special Trees. January 14, 2016Borahan Tümer, Ph.D.2 Outline Adelson-Velskii-Landis (AVL) Trees Splay Trees B-Trees.
CIS 068 Welcome to CIS 068 ! Lesson 12: Data Structures 3 Trees.
B-TREE. Motivation for B-Trees So far we have assumed that we can store an entire data structure in main memory What if we have so much data that it won’t.
Internal and External Sorting External Searching
Lecture 10COMPSCI.220.FS.T Binary Search Tree BST converts a static binary search into a dynamic binary search allowing to efficiently insert and.
MA/CSSE 473 Day 30 B Trees Dynamic Programming Binomial Coefficients Warshall's algorithm No in-class quiz today Student questions?
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?
ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: ec2620m.htm Office: TEL 3049.
Different Tree Data Structures for Different Problems
B-Tree Michael Tsai 2017/06/06.
Azita Keshmiri CS 157B Ch 12 indexing and hashing
Indexing ? Why ? Need to locate the actual records on disk without having to read the entire table into memory.
B+ Trees What are B+ Trees used for What is a B Tree What is a B+ Tree
Binary Search Tree Chapter 10.
COP3530- Data Structures B Trees
Wednesday, April 18, 2018 Announcements… For Today…
Lecture 26 Multiway Search Trees Chapter 11 of textbook
B-Trees (continued) Analysis of worst-case and average number of disk accesses for an insert. Delete and analysis. Structure for B-tree node.
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Binary SearchTrees [CLRS] – Chap 12.
B-Trees B-trees are characterized in the following way:
Presentation transcript:

Different Tree Data Structures for Different Problems

Data Structures Data Structures have to be adapted for each problem: A specific subset of operations (Example: Search is needed, Insert is not) A specific set of requirements or usage patterns (Example: Search occurs frequently, Insert occurs rarely) Special Data Structures Hybrid data structures Augmented data structures

Problem 1 Problem: Dictionary, where every key has the same probability to be searched for and the structure must be dynamic (inserts and deletes) Solution: we have seen that we can use Balanced Binary Search Trees

Problem 2 Problem: Dictionary, where every key has a different, known probability to be searched for; the structure is not dynamic. Example: A dictionary must contain words: bag, cat, dog, school. It is known that school gets searched 40% of the time, bag 30% of the time, dog 20% of the time and cat 10% of the time. The keys which are more frequent searched for must be near the root. Balancing for reducing height does not help here ! Solution: build the Optimal Binary Search Tree

Optimal Binary Search Tree Balanced BST 0.1 Optimal BST 0.4 cat school 0.3 0.2 0.3 bag dog bag 0.2 0.4 dog school 0.1 cat 0.1 * 0 + 0.3*1+ 0.2* 1 + 0.4*2 = 1.3 0.4 * 0 + 0.3*1+ 0.2* 2 + 0.1*3 = 1.0

Problem 3 Problem: A dictionary structure, used to store a dynamic set of words that may contain common prefixes. Solution: We can exploit the common prefixes of the words, and associate the words with paths in a tree instead of nodes of a tree Solution: Trie trees (Prefix trees, Retrieval trees) Multipath trees If the alphabet has R symbols, a node may have R children

Trie Tree B S E E H Y A L E E N L Word set: BE, BY, SEA, SEE, SEEN, SELL, SHE

Problem 4 Problem: we need a data structure having features similar to the search trees (search, insert, delete) but on the secondary storage (disk). What is different with disks? Disks are slow, thus read/write happens in bulk (several items at once, forming a page) Solution: Adapt the BST data structure to a search tree that may contain in a node several keys, up to fill up a page => B-Trees

B-Tree 8 13 17 11 15 22 25 27 4 5 6 Minimum degree of a B-tree: t>=2, such that every node, except the root, must have n keys and n+1 children, where t<=n+1<=2t 2-3-4 trees are actually B-trees of min degree 2 The value of t must be in concordance with the size of the disk page

B-Trees – formal definition A B-tree T is a rooted tree (whose root is T.root) having the properties: Every node x has the following attributes: x.n, the number of keys currently stored in node x, the x.n keys themselves, x.key1, x.key2, …, x.keyx.n, stored in nondecreasing order, so that x.key1 <= x.key2 <= … <= x.keyx.n x.leaf , a boolean value that is TRUE if x is a leaf and FALSE if x is an internal node. Each internal node x also contains x.n+1 pointers x.c1, x.c2, … x.cx.n+1 to its children. Leaf nodes have no children, and so their ci attributes are undefined. The keys x.keyi separate the ranges of keys stored in each subtree: if ki is any key stored in the subtree with root x.ci, then k1 <= x.key1 <= k2 <= x.key2 <= … <= X.keyx.n <= kx.n+1 All leaves have the same depth, which is the tree’s height h. Nodes have lower and upper bounds on the number of keys they can contain. We express these bounds in terms of a fixed integer t >=2 called the minimum degree of the B-tree: Every node other than the root must have at least t -1 keys. Every internal node other than the root thus has at least t children. If the tree is nonempty, the root must have at least one key. Every node may contain at most 2t -1 keys. Therefore, an internal node may have at most 2t children.

Problem 5 Problem: we need a data structure combining the features of both Binary Search Trees and Heaps, holding nodes that have both a search key and a priority Binary Search Trees and Heaps both come in form of Binary Trees Solution: Treap – a Binary Tree where the nodes satisfy both the BST property and the Heap property ! Why is this structure important ? Building a Treap by using random generated values as priorities is a method for building a balanced binary tree

Treap