Relational Database Systems 2 4. Trees & Advanced Indexes

Size: px
Start display at page:

Download "Relational Database Systems 2 4. Trees & Advanced Indexes"

Transcription

1 Relational Database Systems 2 4. Trees & Advanced Indexes Christoph Lofi Benjamin Köhncke Institut für Informationssysteme Technische Universität Braunschweig

2 2 Storage Buffer Management is very important Holds DB blocks in primary memory DB block are made up of several FS blocks Find good strategies to have requested DB blocks available when needed Each block holds some meta data and row data Indexes drastically speed up queries Less blocks need to be scanned Primary Index On primary key attribute, usually influences row storage order Secondary Index On any attribute, does not influence storage order Relational Database Systems 2 Christoph Lofi - Benjamin Köhncke Institut für Informationssysteme 2

3 4 Trees & Advanced Indexes 4.1 Introduction 4.2 Binary Search Trees 4.3 Self Balancing Binary Search Trees 4.4 B-Trees Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 3

4 4.1 Introduction Indexes need a suitable data structure For efficient index look-ups search keys need to be ordered Remember: All indexes should be stored in a separate database file, not together with data A suitable number of DB blocks (adjacent on disk) is reserved at index creation time If the space is not sufficient, another file is created and linked to the original index file Search Key 1 Block Address 1 Search Key 2 Block Address 2 Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 4

5 4.1 Introduction Search within an index Bisection search possible: log 2 n ; O(log n) But usually indexes span several DB blocks If index is in n blocks, O(n) blocks need to be read from disk Example: search for Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 5

6 4.1 Introduction Maintenance of index is also difficult Insert a new search key with value 5! In worst case, all cells need to be shifted and all blocks need to be accessed Similar problem occurs when deleting a value Often: do not shift values, but mark key as deleted Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 6

7 4.1 Introduction In this lecture, we discuss more efficient multilevel data structures B-trees Prevalent in database systems Better access performance Much better update performance To understand B-trees better, we start by examining binary search trees Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 7

8 4.2 Binary Trees Binary trees are Rooted and directed trees Each node has none, one or two children Each node (except root) has exactly one parent 0/1 Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 8

9 4.2 Binary Trees Some naming conventions Nodes without children are called leaf nodes The depth of node N is the path length from the root The tree height is the maximum node depth If there is a path from node N1 to node N2, N1 is an ancestor of N2 and N2 is a descendant of N1 The size of a node N is the number of all descendants of N including itself A subtree of a node N is formed of all descendant nodes including N and the respective links root subtree red red Leaf nodes tree height = 3 red node: size = 3 depth = 1 Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 9

10 4.2 Binary Trees Properties of binary trees Full binary tree (or proper) Each node has either zero or two children Perfect binary tree All leaf nodes have the same depth With height h, contains 2 h nodes Height-balanced binary tree Depth of all leaf nodes differ by at most 1 With height h, contains between 2 h-1 and 2 h nodes Degenerated binary tree Each node has either zero or one child Behaves like a linked list: search in O(n) Full and Balanced Full and Perfect Degenerated Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 10

11 4.2 Binary Search Trees Binary search trees are binary trees with Each node has a unique value assigned There is a total order on all values Left subtree of a node contains only values less than node value Right subtree of a node contains only values larger than the node value Aiming for O(log n) search complexity Structurally resembles bisection search / Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 11

12 4.2 Binary Search Trees Constructing and inserting into binary search trees Values are inserted incrementally First value is root Additional values sink into tree Sink to left subtree if value smaller Sink to right subtree if value larger Attach to last node as left/right child, if subtree is empty Insert order of values does highly influence resulting and intermediate tree properties Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 12

13 4.2 Binary Search Trees Suppose insert order 57, 33, 42, 85, 17, 61, Insert Insert 33, 42 Degenerated Insert 85, 17 Full and Balanced Insert 61, 99 Perfect and Full Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 13

14 4.2 Binary Search Trees Suppose insert order 99, 85, 61, 57, 42, 33, Insert complexity is thus O(n) worst case O(log n) average case Degenerated Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 14

15 4.2 Binary Search Tree Search for a Key Start with root Recursive Procedure If node value = v Return node If node is leaf Value not found if v < node value Descend to left subtree Else Descend to right subtree Complexity: Average case: O(log n) Worst case: O(n) degenerated tree Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 15

16 4.2 Binary Search Tree Tree Traversal Accesses all nodes of the tree Pre-Order Visit node Traverse left subtree Traverse right subtree In-Order (sorted access) Traverse left subtree Visit node Traverse right subtree Post-Order Traverse left subtree Traverse right subtree Visit node Pre-Order: In-Order: Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 16

17 4.2 Binary Search Tree Deleting nodes has complexity O(n) worst case, O(log n) average case Locate the node to delete by tree search If node is leaf, just delete it If node has one child, delete node and attach child to parent If node has two children Replace either by a) in-order successor (the left-most child of the right subtree) b) in-order predecessor (the right-most child of the left subtree) Example: delete search key with value 57 a) b) Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 17

18 4.2 Binary Search Trees Summary Very simple, dynamic data structure Efficient on average O(log n) for all operations Can be very inefficient for degenerated cases O(n) for all operations 0/1 Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 18

19 4.3 Self-Balancing Binary Search Trees Observation: Binary Search Trees are very efficient when perfect or balanced Idea: Continuously optimize tree structure to keep tree balanced Popular Implementations AVL-Tree (classic example) Red-Black-Tree Splay-Tree Scapegoat-Tree Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 19

20 4.3 Self-Balancing Binary Search Trees Basic Concepts for Deletion: Global Rebuild (Lazy Deletion) Start with balanced tree Don t delete a node, just mark it as deleted Search algorithm scans deleted nodes, but does not return them If Rebuild Condition is met, rebuild the whole tree without the deleted nodes Rebuild as soon as half of the nodes are marked as deleted Complete rebuild can be performed in O(n) Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 20

21 4.3 Self-Balancing Binary Search Trees Global Rebuild (cont.) Search Efficiency n number of unmarked nodes Tree is balanced, contains max 2n nodes overall Number of accesses during search usually just increases by 1 O(log n) Delete Efficiency Global rebuild is in O(n) But only necessary after n deletions Amortized additional costs per deletion is O(1) Overall complexity Average: O(log n) Worst Case: O(n), if actual rebuild is performed Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 21

22 4.3 Self-Balancing Binary Search Trees Global Rebuild (cont.) Direct Deletion with Rebuild Similar complexity as with lazy deletion Increased per delete effort Reduced per search effort until rebuild Delete nodes as in normal binary trees Increment deletion counter c d Rebuild tree as soon as c d = n, reset c d Delete 57,33,42,61 Rebuild Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 22

23 4.3 Self-Balancing Binary Search Trees Basic Concepts for Insertion and Deletion: Local Balancing (Subtree Balancing) Start with balanced tree Insert/delete nodes normally If a subtree becomes too unbalanced, locally balance subtree to regain global balance Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 23

24 4.3 Self-Balancing Binary Search Trees To detect unbalanced subtrees, each node v needs to know the size v and the height h(v) of it s subtree Unbalanced Condition: (Height Balancing) Subtree is too unbalanced when h(left(v)) - h(right(v)) > α α is a constant which can be adjusted (for AVL, α=1) Alternative Unbalanced Condition: Subtree is too unbalanced when h(v) > α * log 2 v α is a constant which can be adjusted Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 24

25 4.3 Self-Balancing Binary Search Trees Local Balancing (cont.) After inserting a node, walk back the tree and update stored subtree statistics h(v) and v. If node v is too imbalanced, balance subtree of v 57 2, , 6 Height Imbalanced for α=1 2-0 = 2 > , , , , , , 1 key 17 1, , 1 h(v) v 5 0, 1 Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 25

26 4.3 Self-Balancing Binary Search Trees Local Balancing can be archived by Rebuilding the subtree O( v ) = O(n) the worst case However, O(log n) in average This operation is expensive. But in the context of DBMS, it may pay off as it can also consolidate and optimize physical storage locations Especially suited for disk based trees Rotating Only pointers are moved very efficient O(1) Does not change physical storage of nodes Especially suited for main-memory-based trees Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 26

27 4.3 Self-Balancing Binary Search Trees Local Balancing Rotating Simple Rotation (left, right) Pivot y right x x 3 1 y 1 2 left 2 3 Double Rotation (left-left, right-right, Rollercoaster) z right-right y right-right x y 4 x z 1 y x z 1 2 left-left left-left 3 4 Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 27

28 4.3 Self-Balancing Binary Search Trees Local Balancing Rotating Double Rotation (left-right, Zig-Zag) z left z right x y 4 x 4 y z 1 x y Double Rotation (right-left, Zig-Zag) Analogous to left-right Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 28

29 Self-Balancing Binary Search Trees The presented concepts can be combined in different ways to implement self-balancing trees AVL-Tree (classic example) Red-Black-Tree Splay-Tree Scapegoat-Tree Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 29

30 Self-Balancing Binary Search Trees Implementation: AVL-Trees Invented 1962 by Adelson-Velsky and Landis Uses Local Rebalancing with Rotations for Insertion and Deletion Unbalanced criterion: h(left(v)) - h(right(v)) > 1 Height difference of left and right subtree of v is 2 or more Height information is stored explicitly within nodes Update backtracking after each insert and delete Storage overhead of O(n) Guaranteed maximum height of 1.44 log 2 n Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 30

31 Self-Balancing Binary Search Trees Implementation: Scapegoat-Trees Invented 1993 by Galperin and Rivest Uses Global Rebuilding for Deletions Local Balancing with Rotations for Insertions Unbalanced criterion: h(v) > log 1/α v + 1; 0.5 α 1 Node statistics (height, size) determined dynamically during backtracking Only global statistics are stored Storage overhead of O(1) Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 31

32 4.4 Problems with Binary Search Trees Are binary trees really suitable for disk based databases? Yes and No Binary Trees are great data-structures for usage in internal memory But they have a very bad performance when stored on external storage (i.e. hard disks) 0/1 & = Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 32

33 4.4 Problems with Binary Search Trees Binary tree nodes have to be stored within hard disk blocks in linear fashion When tree is large, nodes are scattered among the blocks In worst case, a new block must be read from disk for every node accessed during search or traversal Every linearization scheme for binary trees has that problem Reading a block from disk is very expensive Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 33

34 4.4 Problems with Binary Search Trees Sample linearization Search for 42 In worst case needs to fetch 3 blocks from disk for just 4 nodes Problem is even worse for full tree traversal Tree: Disk/DB Blocks: Block 1 Block 2 Block 3 Block 4 Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 34

35 4.4 B-Trees B-Trees adapt concepts and techniques learned for binary trees and optimize them for harddisc storage Basic Ideas: Searching within a DB/disk block is very efficient Take advantage of static nature within a block Search can be performed in memory with bisection search Treat entire blocks as tree nodes Reading blocks from the disk is expensive Reduce block reads Most data resides in the leaf nodes Thus minimize the height of the tree Dramatically increase fan-out factor Tree becomes bushy Smaller serach path length Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 35

36 4.4 Block Search Trees First Improvement: Block Search Tree Nodes are complete DB blocks Each node can store up to q pointers p i and q-1 unique and ordered key entries k i : <p 1, k 1,, k q-1, p q > k i < k i+1 Pointers p i link to subtrees (or are empty). All keys in subtree of p i are less than k i and greater as k i-1 Node Pointers Key Value Node EN Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 36

37 4.4 Block Search Trees Locate a key k Recursive Procedure: Start with root node Use bisection search within the current node If key found Return it If key not found If there is a p i with k i-1 < k < k i» Follow p i and repeat algorithm with link node Else» Key not in tree Example: Locate EN Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 37

38 4.4 Block Search Trees Insert a key k Recursive Procedure: Start with root node Use bisection search within the current node If key found Key cannot inserted twice, abort If key not found If there is a p i with k i-1 < k < k i» Follow p i and repeat algorithm with link node Else» If there is space left in the node Insert key and restore sort order» Else Create new, empty node Insert k into new node Link new node to p i in current node such that with k i-1 < k < k i EN Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 38

39 4.4 Block Search Trees Insert a key : EN Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 39

40 4.4 Block Search Trees Delete a key k Start with root node Locate k If k is in leaf node, delete k from node and restore order If leaf node is now empty, delete the node If k is in internal node If no or only one directly adjacent pointer of k are used» Delete k and restore order If k is a separator between two used pointers,» If space in both subnodes is sufficient Union both nodes into one Delete k and restore order» Else Replace k with new separator key Either largest key in left node or smallest key in right node Any completely empty node is deleted as in binary search trees EN Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 40

41 4.4 Block Search Trees Delete a key : EN Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 41

42 4.4 Block Search Trees Delete a key : EN Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 42

43 4.4 Block Search Trees Delete a key : EN Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 43

44 4.4 Block Search Trees Block Search Trees have similar properties to Binary Search Trees Can be perfect, balanced or degenerated Assume height h=3; fan-out-factor q=2048; and total number of keys n Block Search Tree One node can store up to 2047 keys and 2048 links Perfect : n = 8581M Balanced : 4M n 8581M Degenerated : n = 6141 Binary Search Tree (Block tree with q=2) One node can store 1 key and up to 2 links Perfect : n = 7 Balanced : 3 < n 7 Degenerated : n = 3 Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 44

45 4.4 Block Search Trees Assume n = 1,000,000,000; fan-out-factor q=2048; and height h Block Search Tree Balanced : h = 3 Degenerated : h = 488,520 Binary Search Tree Balanced : h = 30 Degenerated : h = 1,000,000,000 During search, there is one disk access per tree height in worst case In this example, block search trees are already 10 times more efficient when balanced, 2000 times when unbalanced Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 45

46 4.4 Block Search Trees Summary BST Data structure optimized for disk storage Is very efficient in average case O(log n) for all operations Even better Average node-accesses to locate a key is log fan-out n» Fan-out usually in the order of several thousands» Binary tree averages only to log 2 n Accessing a node is expensive on disks, huge improvement Can be very inefficient for degenerated cases O(n) for all operations Better than binary trees, but still bad Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 46

47 4.4 B-Trees B-Tree are specialized Block Search Trees for disc-based Indexing Invented by Rudolf Bayer in 1971 Keys may be non-unique Tree is self-balancing No degenerated cases anymore EN Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 47

48 4.4 B-Trees Basic structure of a B-tree node Nodes contain key values and respective data (block) pointers to the actual data records Additionally, there are node pointers for the left, resp. right interval around a key value Key Value Data Pointer Tree Node Node Pointers Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 48

49 1, Adams, $ 887,00 2, Bertram, $19,99 3, Behaim, $ 167,00 4, Cesar, $ 1866,00 5, Miller, $179,99 6, Naders, $ 682,56 7, Ruth, $ 8642,78 8, Smith, $675,99 9, Tarrens, $ 99, B-Trees B-Trees as Primary Index EN Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 49

50 4.4 B-Trees All base operations similar to Block Search Tree with small changes Guaranteed fill degree Self-Balancing Each node contains between L(ower) and U(pper) links Usually 2* L = U Nodes are split during insertion as soon as they contain more than U-2 keys Nodes are unioned during deletion as soon as they contain less than L keys If complete node is created or deleted, use local rebalancing to re-balance tree Local rebuilding for disk-based storage, rotations for memory based storage EN Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 50

51 4.4 B-Trees All insertions start at the leaf nodes Search the tree to find leaf node where new element should be added If the leaf node contains fewer than the maximum legal number of elements (if leaf node < U) Insert the new element in the node and restore order Otherwise the leaf node is split into two nodes (node split) The median is chosen from among the leaf's elements and the new element Values less than the median are put in the new left node and values greater than the median are put in the new right node, with the median acting as a separation value That separation value is added to the node's parent, which may also cause it to be split If the splitting goes all the way up to the root, it creates a new root with a single separator value and two children Remember: the lower bound on the size of internal nodes does not apply to the root Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 51

52 4.4 B-Trees Deleting elements is problematic, because node sizes can decrease under the minimum number of elements (i.e. new node size < L) An element to be deleted in an internal node may be a separator for its child nodes Deletion from a leaf node Search for the value to delete If the value is in a leaf node, it can simply be deleted from the node Test if node has too few elements; in that case the tree has to be rebalanced Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 52

53 4.4 B-Trees Rebalancing after deletion If some leaf node is under the minimum size, some elements must be redistributed from its siblings to bring all children nodes again up to the minimum (stealing) If all siblings have only minimum size, the parent node is affected and has to hand over an element If the parent then falls under the minimum size, the redistribution must be applied iteratively up the tree Since the minimum element count does not apply to the root, making the root the only deficient node is not a problem Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 53

54 4.4 B-Trees The rebalancing strategy is to find a sibling of the deficient node which has more than the minimum number of elements (for stealing) Choose a new separator Move it to the parent node and redistribute the values in both original nodes to the new left and right children If the sibling node to the right of the deficient node has only the minimum number of elements, examine the sibling node to the left Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 54

55 4.4 B-Trees If both siblings have only the minimum number of elements: create a new node with all the elements from the deficient node & all the elements from one of its siblings & the separator in the parent between the two combined sibling nodes Remove the separator from the parent, and replace the two children it separated with the combined node. If that brings the number of elements in the parent under the minimum, repeat these steps with that deficient node, unless it is the root, since the root may be deficient Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 55

56 4.4 B-Trees Example: Steal Keys from Siblings (l=3) Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 56

57 4.4 B-Trees Example: Join Child Nodes (l=3) Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 57

58 4.4 B-Trees Each element in an internal node acts as a separation value for two subtrees. When such an element is deleted, there are two cases: Both of the two child nodes to the left and right of the deleted element have the minimum number of elements (L-1) and then can then be joined into a legal single node with (2L-2) elements One of the two child nodes contains more than the minimum number of elements. Then a new separator for those subtrees must be found. There are two possible choices: The largest element in the left subtree is the largest element which is still less than the separator The smallest element in the right subtree is the smallest element which is still greater than the separator Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 58

59 4.4 B-Trees Deletion from an internal node If the value is in an internal node, choose a new separator, remove it from the leaf node it is in, and replace the element to be deleted with the new separator This has deleted an element from child node so the deletion has been passed down the tree iteratively If the child is a leaf node the leaf node deletion procedure applies Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 59

60 4.4 B-Trees Example: Build a B-Tree Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 60

61 4.4 B-Trees Summary Very efficient data structure for disk storage O(log n) for all operations Even better Guaranteed maximum node-accesses to locate a key is Balanced binary tree guarantees only log 2 n) log fan out ( n ) Accessing a node is expensive on disks huge improvement No degenerated cases Self-Balancing rarely necessary as most updates affect just one node Wasted space decreased due to guaranteed minimal fill factor EN Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 61

62 4.4 B*Trees The B*Tree is a constrained B-Tree All non-root nodes need to be filled to 2/3 Implemented in various file systems HFS Raiser 4 Used to be quite popular, but lost its importance EN Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 62

63 4.4 B + Trees The B + Tree is an optimization of the B-Tree Improved traversal performance Increased search efficiency Increased memory efficiency B + Tree uses different nodes for leaf nodes and internal nodes Internal Nodes: Only unique keys and node links No data pointers! Leaf Nodes: Replicated keys with data pointer Data pointers only here Node Pointer Key Value Key Value Data Pointer EN Node Internal Node Leaf Node Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 63

64 4.4 B + Trees Internal Nodes are used for search guidance A block can contain more keys fan-out higher Leafs just contain data links All leafs are linked to each other in-order for increased traversal performance Internal Search Nodes Data Nodes EN Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 64

65 4.4 B + Trees Summary B + Tree is THE super index structure for disk-based databases Improved over B-Tree Improved traversal performance Increased search efficiency Increased memory efficiency EN Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 65

66 4.5 IMDB s Observation Loading data from the hard disk is a major bottleneck Available main memory still doubles every 18 month Moore s Law Idea Store all data in fast main memory! Solutions Use traditional DBMS with huge buffer pool (block cache) DBMS are usually optimized for sequential disk access Design special In-Memory Databases Systems Or MMDB (Main Memory Database) Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 66

67 4.5 IMDB s Why do we need in-memory databases? Embedded Systems Mobile Phones PDA s Sensors Diskless Computing Devices Ultra-High-Performance (Real Time) Scenarios Network Applications Telecommunication Applications High-Volume Trading Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 67

68 4.5 IMDB s Why should IMDB s be different? Traditional DBMS do also work in-memory but they waste potential Random access has nearly no penalty compared to sequential access Optimizing for linear storage and block read/write unnecessary Type Media Size Random Acc. Speed Transfer Speed Characteristics Price Price/GB Pri DDR3-Ram (Corsair 1600C7DHX) 2 GiB ms 8000 MB/sec Vol, Dyn, Ra, OL Sec Harddrive Magnetic (Seagate ST AS) 2000 GB < 8.5 ms 138 MB/sec Stat, RA, OL Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 68

69 4.5 IMDB s Storing a DB in main memory also has problems Main memory usually smaller and more expensive ACID support IMDBs support atomicity, consistency and isolation Problem: main memory is not persistent What happens in case of power failure? How to ensure the durability requirement of DBs? Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 69

70 4.5 IMDB s - Durability Snapshot Files / Checkpoint Images Record state of DB at given point in time Done periodically or in case of controlled shutdown Only partial durability Transaction Logging History of actions executed by the DBMS File of changes done in the database stored in stable storage If DB has not been shut down properly (respectively is in inconsistent state) the DBMS reviews logs for uncommitted transactions and rolls back changes Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 70

71 4.5 IMDB s - Durability Non-volatile random access memory (NVRAM) Static RAM backed up with battery power (battery RAM) Or electrically erasable programmable ROM (EEPROM) Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 71

72 4.5 IMDB s - Indexes IMDB Index Structures B-Trees are great, but they are shallow and bushy which is unnecessary in main memory Can save some performance there Hash Indexes are very suitable in main memory for unsorted data Especially bucket chained hashing is very efficient For sorted data: Use the T-Tree instead of B-Tree Specialized tree for main memory databases Blend between AVL-Tree and B-Tree Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 72

73 4.5 T-Tree T-Tree design considerations I/O access is cheap in main memory Expensive resources are computation time and memory space Properties T-Tree is a self-balancing binary tree (AVL algorithm) T-Tree nodes contain only links Each node links to m data records (d 1 d m ) Data entries are ordered, smallest left, biggest right All nodes contain a maximum of c max entries Each internal node contains c min to c max entries (usually c max -c min 2) Each node has a link to it s parent Each node has at most a left and a right subtree Left subtree contains only entries smaller than the minimal node entry Right subtree contains only entries bigger than maximal node entry d 1 p d 2 d m-1 d m l r Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 73

74 4.5 IMDB Indexes How do main memory index structures compare? Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 74

75 4.5 IMDB Indexes How do main memory index structures compare? Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 75

76 4.5 IMDB Indexes How do main memory index structures compare? Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 76

77 4.5 IMDB Indexes Why not always use Chained Bucked Hashing? No range queries Storage overhead Suboptimal if amount of data is unknown during initialization Why do T-Tree and AVL-Tree perform better than B- Tree and ordered array for search? Bisection search within a B-tree node/array needs to compute position of next comparison AVL and T-Tree do only need 2 comparisons in each node Why does T-Tree perform better than AVL for updates? Due to larger nodes, many updates do not require a rebalancing Why does ordered array suck for updates? Reordering of all elements necessary for each update Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 77

78 4.5 References and Timeline AVL-Tree G. Adelson-Velskii, E. M. Landis: An algorithm for the organization of information. Proceedings of the USSR Academy of Sciences 146: (Russian), English translation by M. J. Ricci in Soviet Math. Doklady, 3: , 1962 B-Trees R. Bayer, E. M. McCreight: Organization and Maintenance of Large Ordered Indexes. Acta Informatica 1, , 1972 T-Trees T. J. Lehman, M. J. Carey: A Study of Index Structures for Main Memory Database Management Systems, Int. Conf. On Very Large 12th Database, Kyoto, August 1986 Scapegoat Trees I. Galperin, R. L. Rivest: Scapegoat trees, ACM-SIAM Symposium on Discrete Algorithms, Austin, Texas, US, 1993 Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 78

79 4 Storage Tree data structures are good index structures O(log n ) performance in average But they may degenerate O(n) Balancing necesarry! Block structure of hard discs must be considered Block trees B-Tree Self-balancing block tree with fill-guarantees B+-Tree Special inner nodes without data pointers Leaf nodes optimized for linear traversal Relational Database Systems 2 Christoph Lofi - Benjamin Köhncke Institut für Informationssysteme 79

80 5 Outlook The Query Processor How do DBMS actually answer queries? Query Parsing/Translation Query Optimization Query Execution Implementation of Joins Datenbanksysteme 2 Christoph Lofi Institut für Informationssysteme TU Braunschweig 80

From Last Time: Remove (Delete) Operation

From Last Time: Remove (Delete) Operation CSE 32 Lecture : More on Search Trees Today s Topics: Lazy Operations Run Time Analysis of Binary Search Tree Operations Balanced Search Trees AVL Trees and Rotations Covered in Chapter of the text From

More information

Previous Lectures. B-Trees. External storage. Two types of memory. B-trees. Main principles

Previous Lectures. B-Trees. External storage. Two types of memory. B-trees. Main principles B-Trees Algorithms and data structures for external memory as opposed to the main memory B-Trees Previous Lectures Height balanced binary search trees: AVL trees, red-black trees. Multiway search trees:

More information

Binary Search Trees. Data in each node. Larger than the data in its left child Smaller than the data in its right child

Binary Search Trees. Data in each node. Larger than the data in its left child Smaller than the data in its right child Binary Search Trees Data in each node Larger than the data in its left child Smaller than the data in its right child FIGURE 11-6 Arbitrary binary tree FIGURE 11-7 Binary search tree Data Structures Using

More information

Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb

Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb Binary Search Trees Lecturer: Georgy Gimel farb COMPSCI 220 Algorithms and Data Structures 1 / 27 1 Properties of Binary Search Trees 2 Basic BST operations The worst-case time complexity of BST operations

More information

B-Trees. Algorithms and data structures for external memory as opposed to the main memory B-Trees. B -trees

B-Trees. Algorithms and data structures for external memory as opposed to the main memory B-Trees. B -trees B-Trees Algorithms and data structures for external memory as opposed to the main memory B-Trees Previous Lectures Height balanced binary search trees: AVL trees, red-black trees. Multiway search trees:

More information

DATABASE DESIGN - 1DL400

DATABASE DESIGN - 1DL400 DATABASE DESIGN - 1DL400 Spring 2015 A course on modern database systems!! http://www.it.uu.se/research/group/udbl/kurser/dbii_vt15/ Kjell Orsborn! Uppsala Database Laboratory! Department of Information

More information

Converting a Number from Decimal to Binary

Converting a Number from Decimal to Binary Converting a Number from Decimal to Binary Convert nonnegative integer in decimal format (base 10) into equivalent binary number (base 2) Rightmost bit of x Remainder of x after division by two Recursive

More information

A Comparison of Dictionary Implementations

A Comparison of Dictionary Implementations A Comparison of Dictionary Implementations Mark P Neyer April 10, 2009 1 Introduction A common problem in computer science is the representation of a mapping between two sets. A mapping f : A B is a function

More information

Big Data and Scripting. Part 4: Memory Hierarchies

Big Data and Scripting. Part 4: Memory Hierarchies 1, Big Data and Scripting Part 4: Memory Hierarchies 2, Model and Definitions memory size: M machine words total storage (on disk) of N elements (N is very large) disk size unlimited (for our considerations)

More information

Binary Search Trees CMPSC 122

Binary Search Trees CMPSC 122 Binary Search Trees CMPSC 122 Note: This notes packet has significant overlap with the first set of trees notes I do in CMPSC 360, but goes into much greater depth on turning BSTs into pseudocode than

More information

Chapter 13: Query Processing. Basic Steps in Query Processing

Chapter 13: Query Processing. Basic Steps in Query Processing Chapter 13: Query Processing! Overview! Measures of Query Cost! Selection Operation! Sorting! Join Operation! Other Operations! Evaluation of Expressions 13.1 Basic Steps in Query Processing 1. Parsing

More information

Lecture 1: Data Storage & Index

Lecture 1: Data Storage & Index Lecture 1: Data Storage & Index R&G Chapter 8-11 Concurrency control Query Execution and Optimization Relational Operators File & Access Methods Buffer Management Disk Space Management Recovery Manager

More information

CSE 326: Data Structures B-Trees and B+ Trees

CSE 326: Data Structures B-Trees and B+ Trees Announcements (4//08) CSE 26: Data Structures B-Trees and B+ Trees Brian Curless Spring 2008 Midterm on Friday Special office hour: 4:-5: Thursday in Jaech Gallery (6 th floor of CSE building) This is

More information

Persistent Binary Search Trees

Persistent Binary Search Trees Persistent Binary Search Trees Datastructures, UvA. May 30, 2008 0440949, Andreas van Cranenburgh Abstract A persistent binary tree allows access to all previous versions of the tree. This paper presents

More information

In-Memory Databases MemSQL

In-Memory Databases MemSQL IT4BI - Université Libre de Bruxelles In-Memory Databases MemSQL Gabby Nikolova Thao Ha Contents I. In-memory Databases...4 1. Concept:...4 2. Indexing:...4 a. b. c. d. AVL Tree:...4 B-Tree and B+ Tree:...5

More information

Analysis of Algorithms I: Binary Search Trees

Analysis of Algorithms I: Binary Search Trees Analysis of Algorithms I: Binary Search Trees Xi Chen Columbia University Hash table: A data structure that maintains a subset of keys from a universe set U = {0, 1,..., p 1} and supports all three dictionary

More information

Learning Outcomes. COMP202 Complexity of Algorithms. Binary Search Trees and Other Search Trees

Learning Outcomes. COMP202 Complexity of Algorithms. Binary Search Trees and Other Search Trees Learning Outcomes COMP202 Complexity of Algorithms Binary Search Trees and Other Search Trees [See relevant sections in chapters 2 and 3 in Goodrich and Tamassia.] At the conclusion of this set of lecture

More information

A binary search tree is a binary tree with a special property called the BST-property, which is given as follows:

A binary search tree is a binary tree with a special property called the BST-property, which is given as follows: Chapter 12: Binary Search Trees A binary search tree is a binary tree with a special property called the BST-property, which is given as follows: For all nodes x and y, if y belongs to the left subtree

More information

TREE BASIC TERMINOLOGIES

TREE BASIC TERMINOLOGIES TREE Trees are very flexible, versatile and powerful non-liner data structure that can be used to represent data items possessing hierarchical relationship between the grand father and his children and

More information

Databases and Information Systems 1 Part 3: Storage Structures and Indices

Databases and Information Systems 1 Part 3: Storage Structures and Indices bases and Information Systems 1 Part 3: Storage Structures and Indices Prof. Dr. Stefan Böttcher Fakultät EIM, Institut für Informatik Universität Paderborn WS 2009 / 2010 Contents: - database buffer -

More information

S. Muthusundari. Research Scholar, Dept of CSE, Sathyabama University Chennai, India e-mail: nellailath@yahoo.co.in. Dr. R. M.

S. Muthusundari. Research Scholar, Dept of CSE, Sathyabama University Chennai, India e-mail: nellailath@yahoo.co.in. Dr. R. M. A Sorting based Algorithm for the Construction of Balanced Search Tree Automatically for smaller elements and with minimum of one Rotation for Greater Elements from BST S. Muthusundari Research Scholar,

More information

Binary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( B-S-T) are of the form. P parent. Key. Satellite data L R

Binary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( B-S-T) are of the form. P parent. Key. Satellite data L R Binary Search Trees A Generic Tree Nodes in a binary search tree ( B-S-T) are of the form P parent Key A Satellite data L R B C D E F G H I J The B-S-T has a root node which is the only node whose parent

More information

root node level: internal node edge leaf node CS@VT Data Structures & Algorithms 2000-2009 McQuain

root node level: internal node edge leaf node CS@VT Data Structures & Algorithms 2000-2009 McQuain inary Trees 1 A binary tree is either empty, or it consists of a node called the root together with two binary trees called the left subtree and the right subtree of the root, which are disjoint from each

More information

Why Use Binary Trees?

Why Use Binary Trees? Binary Search Trees Why Use Binary Trees? Searches are an important application. What other searches have we considered? brute force search (with array or linked list) O(N) binarysearch with a pre-sorted

More information

How To Create A Tree From A Tree In Runtime (For A Tree)

How To Create A Tree From A Tree In Runtime (For A Tree) Binary Search Trees < 6 2 > = 1 4 8 9 Binary Search Trees 1 Binary Search Trees A binary search tree is a binary tree storing keyvalue entries at its internal nodes and satisfying the following property:

More information

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ Answer the following 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ 2) Which data structure is needed to convert infix notations to postfix notations? Stack 3) The

More information

Chapter 14 The Binary Search Tree

Chapter 14 The Binary Search Tree Chapter 14 The Binary Search Tree In Chapter 5 we discussed the binary search algorithm, which depends on a sorted vector. Although the binary search, being in O(lg(n)), is very efficient, inserting a

More information

Unit 4.3 - Storage Structures 1. Storage Structures. Unit 4.3

Unit 4.3 - Storage Structures 1. Storage Structures. Unit 4.3 Storage Structures Unit 4.3 Unit 4.3 - Storage Structures 1 The Physical Store Storage Capacity Medium Transfer Rate Seek Time Main Memory 800 MB/s 500 MB Instant Hard Drive 10 MB/s 120 GB 10 ms CD-ROM

More information

Symbol Tables. Introduction

Symbol Tables. Introduction Symbol Tables Introduction A compiler needs to collect and use information about the names appearing in the source program. This information is entered into a data structure called a symbol table. The

More information

Ordered Lists and Binary Trees

Ordered Lists and Binary Trees Data Structures and Algorithms Ordered Lists and Binary Trees Chris Brooks Department of Computer Science University of San Francisco Department of Computer Science University of San Francisco p.1/62 6-0:

More information

Physical Data Organization

Physical Data Organization Physical Data Organization Database design using logical model of the database - appropriate level for users to focus on - user independence from implementation details Performance - other major factor

More information

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and: Binary Search Trees 1 The general binary tree shown in the previous chapter is not terribly useful in practice. The chief use of binary trees is for providing rapid access to data (indexing, if you will)

More information

Binary Trees and Huffman Encoding Binary Search Trees

Binary Trees and Huffman Encoding Binary Search Trees Binary Trees and Huffman Encoding Binary Search Trees Computer Science E119 Harvard Extension School Fall 2012 David G. Sullivan, Ph.D. Motivation: Maintaining a Sorted Collection of Data A data dictionary

More information

Data storage Tree indexes

Data storage Tree indexes Data storage Tree indexes Rasmus Pagh February 7 lecture 1 Access paths For many database queries and updates, only a small fraction of the data needs to be accessed. Extreme examples are looking or updating

More information

File System Management

File System Management Lecture 7: Storage Management File System Management Contents Non volatile memory Tape, HDD, SSD Files & File System Interface Directories & their Organization File System Implementation Disk Space Allocation

More information

External Sorting. Why Sort? 2-Way Sort: Requires 3 Buffers. Chapter 13

External Sorting. Why Sort? 2-Way Sort: Requires 3 Buffers. Chapter 13 External Sorting Chapter 13 Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Why Sort? A classic problem in computer science! Data requested in sorted order e.g., find students in increasing

More information

External Memory Geometric Data Structures

External Memory Geometric Data Structures External Memory Geometric Data Structures Lars Arge Department of Computer Science University of Aarhus and Duke University Augues 24, 2005 1 Introduction Many modern applications store and process datasets

More information

Data Warehousing und Data Mining

Data Warehousing und Data Mining Data Warehousing und Data Mining Multidimensionale Indexstrukturen Ulf Leser Wissensmanagement in der Bioinformatik Content of this Lecture Multidimensional Indexing Grid-Files Kd-trees Ulf Leser: Data

More information

Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *

Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * * Binary Heaps A binary heap is another data structure. It implements a priority queue. Priority Queue has the following operations: isempty add (with priority) remove (highest priority) peek (at highest

More information

Binary Heap Algorithms

Binary Heap Algorithms CS Data Structures and Algorithms Lecture Slides Wednesday, April 5, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org 2005 2009 Glenn G. Chappell

More information

Questions 1 through 25 are worth 2 points each. Choose one best answer for each.

Questions 1 through 25 are worth 2 points each. Choose one best answer for each. Questions 1 through 25 are worth 2 points each. Choose one best answer for each. 1. For the singly linked list implementation of the queue, where are the enqueues and dequeues performed? c a. Enqueue in

More information

An Evaluation of Self-adjusting Binary Search Tree Techniques

An Evaluation of Self-adjusting Binary Search Tree Techniques SOFTWARE PRACTICE AND EXPERIENCE, VOL. 23(4), 369 382 (APRIL 1993) An Evaluation of Self-adjusting Binary Search Tree Techniques jim bell and gopal gupta Department of Computer Science, James Cook University,

More information

External Sorting. Chapter 13. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

External Sorting. Chapter 13. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 External Sorting Chapter 13 Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1 Why Sort? A classic problem in computer science! Data requested in sorted order e.g., find students in increasing

More information

Sorting revisited. Build the binary search tree: O(n^2) Traverse the binary tree: O(n) Total: O(n^2) + O(n) = O(n^2)

Sorting revisited. Build the binary search tree: O(n^2) Traverse the binary tree: O(n) Total: O(n^2) + O(n) = O(n^2) Sorting revisited How did we use a binary search tree to sort an array of elements? Tree Sort Algorithm Given: An array of elements to sort 1. Build a binary search tree out of the elements 2. Traverse

More information

M-way Trees and B-Trees

M-way Trees and B-Trees Carlos Moreno cmoreno @ uwaterloo.ca EIT-4103 https://ece.uwaterloo.ca/~cmoreno/ece250 Standard reminder to set phones to silent/vibrate mode, please! Once upon a time... in a course that we all like to

More information

Data Structures Fibonacci Heaps, Amortized Analysis

Data Structures Fibonacci Heaps, Amortized Analysis Chapter 4 Data Structures Fibonacci Heaps, Amortized Analysis Algorithm Theory WS 2012/13 Fabian Kuhn Fibonacci Heaps Lacy merge variant of binomial heaps: Do not merge trees as long as possible Structure:

More information

B+ Tree Properties B+ Tree Searching B+ Tree Insertion B+ Tree Deletion Static Hashing Extendable Hashing Questions in pass papers

B+ Tree Properties B+ Tree Searching B+ Tree Insertion B+ Tree Deletion Static Hashing Extendable Hashing Questions in pass papers B+ Tree and Hashing B+ Tree Properties B+ Tree Searching B+ Tree Insertion B+ Tree Deletion Static Hashing Extendable Hashing Questions in pass papers B+ Tree Properties Balanced Tree Same height for paths

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms CS245-2016S-06 Binary Search Trees David Galles Department of Computer Science University of San Francisco 06-0: Ordered List ADT Operations: Insert an element in the list

More information

- Easy to insert & delete in O(1) time - Don t need to estimate total memory needed. - Hard to search in less than O(n) time

- Easy to insert & delete in O(1) time - Don t need to estimate total memory needed. - Hard to search in less than O(n) time Skip Lists CMSC 420 Linked Lists Benefits & Drawbacks Benefits: - Easy to insert & delete in O(1) time - Don t need to estimate total memory needed Drawbacks: - Hard to search in less than O(n) time (binary

More information

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) 3 4 4 7 5 9 6 16 7 8 8 4 9 8 10 4 Total 92.

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) 3 4 4 7 5 9 6 16 7 8 8 4 9 8 10 4 Total 92. Name: Email ID: CSE 326, Data Structures Section: Sample Final Exam Instructions: The exam is closed book, closed notes. Unless otherwise stated, N denotes the number of elements in the data structure

More information

Exam study sheet for CS2711. List of topics

Exam study sheet for CS2711. List of topics Exam study sheet for CS2711 Here is the list of topics you need to know for the final exam. For each data structure listed below, make sure you can do the following: 1. Give an example of this data structure

More information

Two Parts. Filesystem Interface. Filesystem design. Interface the user sees. Implementing the interface

Two Parts. Filesystem Interface. Filesystem design. Interface the user sees. Implementing the interface File Management Two Parts Filesystem Interface Interface the user sees Organization of the files as seen by the user Operations defined on files Properties that can be read/modified Filesystem design Implementing

More information

Binary Search Trees (BST)

Binary Search Trees (BST) Binary Search Trees (BST) 1. Hierarchical data structure with a single reference to node 2. Each node has at most two child nodes (a left and a right child) 3. Nodes are organized by the Binary Search

More information

Binary Heaps. CSE 373 Data Structures

Binary Heaps. CSE 373 Data Structures Binary Heaps CSE Data Structures Readings Chapter Section. Binary Heaps BST implementation of a Priority Queue Worst case (degenerate tree) FindMin, DeleteMin and Insert (k) are all O(n) Best case (completely

More information

Heaps & Priority Queues in the C++ STL 2-3 Trees

Heaps & Priority Queues in the C++ STL 2-3 Trees Heaps & Priority Queues in the C++ STL 2-3 Trees CS 3 Data Structures and Algorithms Lecture Slides Friday, April 7, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks

More information

Operations: search;; min;; max;; predecessor;; successor. Time O(h) with h height of the tree (more on later).

Operations: search;; min;; max;; predecessor;; successor. Time O(h) with h height of the tree (more on later). Binary search tree Operations: search;; min;; max;; predecessor;; successor. Time O(h) with h height of the tree (more on later). Data strutcure fields usually include for a given node x, the following

More information

File Systems Management and Examples

File Systems Management and Examples File Systems Management and Examples Today! Efficiency, performance, recovery! Examples Next! Distributed systems Disk space management! Once decided to store a file as sequence of blocks What s the size

More information

Algorithms Chapter 12 Binary Search Trees

Algorithms Chapter 12 Binary Search Trees Algorithms Chapter 1 Binary Search Trees Outline Assistant Professor: Ching Chi Lin 林 清 池 助 理 教 授 chingchi.lin@gmail.com Department of Computer Science and Engineering National Taiwan Ocean University

More information

R-trees. R-Trees: A Dynamic Index Structure For Spatial Searching. R-Tree. Invariants

R-trees. R-Trees: A Dynamic Index Structure For Spatial Searching. R-Tree. Invariants R-Trees: A Dynamic Index Structure For Spatial Searching A. Guttman R-trees Generalization of B+-trees to higher dimensions Disk-based index structure Occupancy guarantee Multiple search paths Insertions

More information

Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C Tutorial#1 Q 1:- Explain the terms data, elementary item, entity, primary key, domain, attribute and information? Also give examples in support of your answer? Q 2:- What is a Data Type? Differentiate

More information

Lecture 4: Balanced Binary Search Trees

Lecture 4: Balanced Binary Search Trees Lecture 4 alanced inar Search Trees 6.006 Fall 009 Lecture 4: alanced inar Search Trees Lecture Overview The importance of being balanced VL trees Definition alance Insert Other balanced trees Data structures

More information

6 March 2007 1. Array Implementation of Binary Trees

6 March 2007 1. Array Implementation of Binary Trees Heaps CSE 0 Winter 00 March 00 1 Array Implementation of Binary Trees Each node v is stored at index i defined as follows: If v is the root, i = 1 The left child of v is in position i The right child of

More information

Fundamental Algorithms

Fundamental Algorithms Fundamental Algorithms Chapter 6: AVL Trees Michael Bader Winter 2011/12 Chapter 6: AVL Trees, Winter 2011/12 1 Part I AVL Trees Chapter 6: AVL Trees, Winter 2011/12 2 Binary Search Trees Summary Complexity

More information

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team Lecture Summary In this lecture, we learned about the ADT Priority Queue. A

More information

Chapter 13. Chapter Outline. Disk Storage, Basic File Structures, and Hashing

Chapter 13. Chapter Outline. Disk Storage, Basic File Structures, and Hashing Chapter 13 Disk Storage, Basic File Structures, and Hashing Copyright 2007 Ramez Elmasri and Shamkant B. Navathe Chapter Outline Disk Storage Devices Files of Records Operations on Files Unordered Files

More information

Lecture 2 February 12, 2003

Lecture 2 February 12, 2003 6.897: Advanced Data Structures Spring 003 Prof. Erik Demaine Lecture February, 003 Scribe: Jeff Lindy Overview In the last lecture we considered the successor problem for a bounded universe of size u.

More information

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D. 1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D. base address 2. The memory address of fifth element of an array can be calculated

More information

Raima Database Manager Version 14.0 In-memory Database Engine

Raima Database Manager Version 14.0 In-memory Database Engine + Raima Database Manager Version 14.0 In-memory Database Engine By Jeffrey R. Parsons, Senior Engineer January 2016 Abstract Raima Database Manager (RDM) v14.0 contains an all new data storage engine optimized

More information

Review of Hashing: Integer Keys

Review of Hashing: Integer Keys CSE 326 Lecture 13: Much ado about Hashing Today s munchies to munch on: Review of Hashing Collision Resolution by: Separate Chaining Open Addressing $ Linear/Quadratic Probing $ Double Hashing Rehashing

More information

A Randomized Self-Adjusting Binary Search Tree

A Randomized Self-Adjusting Binary Search Tree A Randomized Self-Adjusting Binary Search Tree Mayur Patel VFX Department Supervisor Animal Logic Film patelm@acm.org We present algorithms for a new self-adjusting binary search tree, which we call a

More information

Data Structure [Question Bank]

Data Structure [Question Bank] Unit I (Analysis of Algorithms) 1. What are algorithms and how they are useful? 2. Describe the factor on best algorithms depends on? 3. Differentiate: Correct & Incorrect Algorithms? 4. Write short note:

More information

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe. Slide 13-1

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe. Slide 13-1 Slide 13-1 Chapter 13 Disk Storage, Basic File Structures, and Hashing Chapter Outline Disk Storage Devices Files of Records Operations on Files Unordered Files Ordered Files Hashed Files Dynamic and Extendible

More information

Chapter 8: Structures for Files. Truong Quynh Chi tqchi@cse.hcmut.edu.vn. Spring- 2013

Chapter 8: Structures for Files. Truong Quynh Chi tqchi@cse.hcmut.edu.vn. Spring- 2013 Chapter 8: Data Storage, Indexing Structures for Files Truong Quynh Chi tqchi@cse.hcmut.edu.vn Spring- 2013 Overview of Database Design Process 2 Outline Data Storage Disk Storage Devices Files of Records

More information

Data Warehousing & Data Mining

Data Warehousing & Data Mining Data Warehousing & Data Mining Wolf-Tilo Balke Silviu Homoceanu Institut für Informationssysteme Technische Universität Braunschweig http://www.ifis.cs.tu-bs.de 8. Real-Time DW 8. Real-Time Data Warehouses

More information

File Management. Chapter 12

File Management. Chapter 12 Chapter 12 File Management File is the basic element of most of the applications, since the input to an application, as well as its output, is usually a file. They also typically outlive the execution

More information

Chapter 13 Disk Storage, Basic File Structures, and Hashing.

Chapter 13 Disk Storage, Basic File Structures, and Hashing. Chapter 13 Disk Storage, Basic File Structures, and Hashing. Copyright 2004 Pearson Education, Inc. Chapter Outline Disk Storage Devices Files of Records Operations on Files Unordered Files Ordered Files

More information

CS711008Z Algorithm Design and Analysis

CS711008Z Algorithm Design and Analysis CS711008Z Algorithm Design and Analysis Lecture 7 Binary heap, binomial heap, and Fibonacci heap 1 Dongbo Bu Institute of Computing Technology Chinese Academy of Sciences, Beijing, China 1 The slides were

More information

The Classical Architecture. Storage 1 / 36

The Classical Architecture. Storage 1 / 36 1 / 36 The Problem Application Data? Filesystem Logical Drive Physical Drive 2 / 36 Requirements There are different classes of requirements: Data Independence application is shielded from physical storage

More information

Overview of Storage and Indexing

Overview of Storage and Indexing Overview of Storage and Indexing Chapter 8 How index-learning turns no student pale Yet holds the eel of science by the tail. -- Alexander Pope (1688-1744) Database Management Systems 3ed, R. Ramakrishnan

More information

5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes. 1. The advantage of.. is that they solve the problem if sequential storage representation. But disadvantage in that is they are sequential lists. [A] Lists [B] Linked Lists [A] Trees [A] Queues 2. The

More information

Lecture 6: Binary Search Trees CSCI 700 - Algorithms I. Andrew Rosenberg

Lecture 6: Binary Search Trees CSCI 700 - Algorithms I. Andrew Rosenberg Lecture 6: Binary Search Trees CSCI 700 - Algorithms I Andrew Rosenberg Last Time Linear Time Sorting Counting Sort Radix Sort Bucket Sort Today Binary Search Trees Data Structures Data structure is a

More information

Home Page. Data Structures. Title Page. Page 1 of 24. Go Back. Full Screen. Close. Quit

Home Page. Data Structures. Title Page. Page 1 of 24. Go Back. Full Screen. Close. Quit Data Structures Page 1 of 24 A.1. Arrays (Vectors) n-element vector start address + ielementsize 0 +1 +2 +3 +4... +n-1 start address continuous memory block static, if size is known at compile time dynamic,

More information

Introduction Advantages and Disadvantages Algorithm TIME COMPLEXITY. Splay Tree. Cheruku Ravi Teja. November 14, 2011

Introduction Advantages and Disadvantages Algorithm TIME COMPLEXITY. Splay Tree. Cheruku Ravi Teja. November 14, 2011 November 14, 2011 1 Real Time Applications 2 3 Results of 4 Real Time Applications Splay trees are self branching binary search tree which has the property of reaccessing the elements quickly that which

More information

CIS 631 Database Management Systems Sample Final Exam

CIS 631 Database Management Systems Sample Final Exam CIS 631 Database Management Systems Sample Final Exam 1. (25 points) Match the items from the left column with those in the right and place the letters in the empty slots. k 1. Single-level index files

More information

O 2 -Tree: A Shared Memory Resident Index in Multicore Architectures

O 2 -Tree: A Shared Memory Resident Index in Multicore Architectures O 2 -Tree: A Shared Memory Resident Index in Multicore Architectures Daniel Ohene-Kwofie Faculty Of Science University Of The Witwatersrand A Dissertation submitted to the Faculty Of Science in fulfilment

More information

Chapter 13. Disk Storage, Basic File Structures, and Hashing

Chapter 13. Disk Storage, Basic File Structures, and Hashing Chapter 13 Disk Storage, Basic File Structures, and Hashing Chapter Outline Disk Storage Devices Files of Records Operations on Files Unordered Files Ordered Files Hashed Files Dynamic and Extendible Hashing

More information

Dynamic 3-sided Planar Range Queries with Expected Doubly Logarithmic Time

Dynamic 3-sided Planar Range Queries with Expected Doubly Logarithmic Time Dynamic 3-sided Planar Range Queries with Expected Doubly Logarithmic Time Gerth Stølting Brodal 1, Alexis C. Kaporis 2, Spyros Sioutas 3, Konstantinos Tsakalidis 1, Kostas Tsichlas 4 1 MADALGO, Department

More information

Lecture Notes on Binary Search Trees

Lecture Notes on Binary Search Trees Lecture Notes on Binary Search Trees 15-122: Principles of Imperative Computation Frank Pfenning André Platzer Lecture 17 October 23, 2014 1 Introduction In this lecture, we will continue considering associative

More information

PES Institute of Technology-BSC QUESTION BANK

PES Institute of Technology-BSC QUESTION BANK PES Institute of Technology-BSC Faculty: Mrs. R.Bharathi CS35: Data Structures Using C QUESTION BANK UNIT I -BASIC CONCEPTS 1. What is an ADT? Briefly explain the categories that classify the functions

More information

The Bi-Objective Pareto Constraint

The Bi-Objective Pareto Constraint The Bi-Objective Pareto Constraint Renaud Hartert and Pierre Schaus UCLouvain, ICTEAM, Place Sainte Barbe 2, 1348 Louvain-la-Neuve, Belgium {renaud.hartert,pierre.schaus}@uclouvain.be Abstract. Multi-Objective

More information

In-Memory Database: Query Optimisation. S S Kausik (110050003) Aamod Kore (110050004) Mehul Goyal (110050017) Nisheeth Lahoti (110050027)

In-Memory Database: Query Optimisation. S S Kausik (110050003) Aamod Kore (110050004) Mehul Goyal (110050017) Nisheeth Lahoti (110050027) In-Memory Database: Query Optimisation S S Kausik (110050003) Aamod Kore (110050004) Mehul Goyal (110050017) Nisheeth Lahoti (110050027) Introduction Basic Idea Database Design Data Types Indexing Query

More information

Data Structure with C

Data Structure with C Subject: Data Structure with C Topic : Tree Tree A tree is a set of nodes that either:is empty or has a designated node, called the root, from which hierarchically descend zero or more subtrees, which

More information

Database Systems. Session 8 Main Theme. Physical Database Design, Query Execution Concepts and Database Programming Techniques

Database Systems. Session 8 Main Theme. Physical Database Design, Query Execution Concepts and Database Programming Techniques Database Systems Session 8 Main Theme Physical Database Design, Query Execution Concepts and Database Programming Techniques Dr. Jean-Claude Franchitti New York University Computer Science Department Courant

More information

Structure for String Keys

Structure for String Keys Burst Tries: A Fast, Efficient Data Structure for String Keys Steen Heinz Justin Zobel Hugh E. Williams School of Computer Science and Information Technology, RMIT University Presented by Margot Schips

More information

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer Computers CMPT 125: Lecture 1: Understanding the Computer Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 A computer performs 2 basic functions: 1.

More information

COS 318: Operating Systems. File Layout and Directories. Topics. File System Components. Steps to Open A File

COS 318: Operating Systems. File Layout and Directories. Topics. File System Components. Steps to Open A File Topics COS 318: Operating Systems File Layout and Directories File system structure Disk allocation and i-nodes Directory and link implementations Physical layout for performance 2 File System Components

More information

Binary Coded Web Access Pattern Tree in Education Domain

Binary Coded Web Access Pattern Tree in Education Domain Binary Coded Web Access Pattern Tree in Education Domain C. Gomathi P.G. Department of Computer Science Kongu Arts and Science College Erode-638-107, Tamil Nadu, India E-mail: kc.gomathi@gmail.com M. Moorthi

More information

APP INVENTOR. Test Review

APP INVENTOR. Test Review APP INVENTOR Test Review Main Concepts App Inventor Lists Creating Random Numbers Variables Searching and Sorting Data Linear Search Binary Search Selection Sort Quick Sort Abstraction Modulus Division

More information

Recovery and the ACID properties CMPUT 391: Implementing Durability Recovery Manager Atomicity Durability

Recovery and the ACID properties CMPUT 391: Implementing Durability Recovery Manager Atomicity Durability Database Management Systems Winter 2004 CMPUT 391: Implementing Durability Dr. Osmar R. Zaïane University of Alberta Lecture 9 Chapter 25 of Textbook Based on slides by Lewis, Bernstein and Kifer. University

More information

Spatial Data Management over Flash Memory

Spatial Data Management over Flash Memory Spatial Data Management over Flash Memory Ioannis Koltsidas 1 and Stratis D. Viglas 2 1 IBM Research, Zurich, Switzerland iko@zurich.ibm.com 2 School of Informatics, University of Edinburgh, UK sviglas@inf.ed.ac.uk

More information