Rrrpdfauthor=Tttpdfsubject
Total Page:16
File Type:pdf, Size:1020Kb
Dipartimento di Informatica Universit`adi Pisa New Combinatorial Properties and Algorithms for AVL Trees Mahdi Amani Under Supervision of Linda Pagli, Anna Bernasconi 3 May 2016 Abstract In this thesis, new properties of AVL trees and a new partitioning of binary search trees named core partitioning scheme are discussed, this scheme is applied to three binary search trees namely AVL trees, weight-balanced trees, and plain binary search trees. We introduce the core partitioning scheme, which maintains a balanced search tree as a dynamic collection of complete balanced binary trees called cores. Using this technique we achieve the same theoretical efficiency of modern cache-oblivious data structures by using classic data structures such as weight-balanced trees or height balanced trees (e.g. AVL trees). We preserve the original topology and algorithms of the given balanced search tree using a simple post-processing with guaranteed performance to completely rebuild the changed cores (possibly all of them) after each update. Using our core partitioning scheme, we simultaneously achieve good memory allocation, space-efficient representation, and cache-obliviousness. We also apply this scheme to arbitrary binary search trees which can be unbalanced and we produce a new data structure, called Cache- Oblivious General Balanced Tree (COG-tree). Using our scheme, searching a key requires O(logB n) block transfers and O(log n) comparisons in the external-memory and in the cache-oblivious model. These complexities are theoretically ef- ficient. Interestingly, the core partition for weight-balanced trees and COG-tree can be maintained with amortized O(logB n) block transfers per update, whereas maintaining the core partition for AVL trees requires more than a poly-logarithmic amortized cost. Studying the properties of these trees also lead us to some other new properties of AVL trees and trees with bounded degree, namely, we present and study gaps in AVL trees and we prove Tarjan et al. 's conjecture on the number of rotations in a sequence of deletions and insertions. Keywords: AVL trees, Weight-balanced tree, External-memory model, Cache-oblivious model, Core partitioning scheme, COG-tree, Gap, AVL rotation. ii Dedication \Thesis topics come and go, but the adventurous styling of the journey is forever." I may not be a religious man, but it is hard to escape the feeling that, underneath all the problems you face in your routine life, there is something of the divine in the solutions you find. I've felt God carrying me when I was stuck and completely lost. This dissertation is dedicated to him and to my wife who shared her patience and support through the hard life of a young researcher. To the compassionate one and to Eli iv Acknowledgments This work could not have been achieved without the help, support, and encouragement of many people. My heartfelt thanks is owed to many people who made this journey possible. My special thanks and appreciation to Prof. Linda Pagli, Prof. Anna Bernasconi, and Prof. Roberto Grossi not only for their help and encouragement throughout my studies, but also for their compassion and empathetic understanding and touching my life during these years that I had the great honor to work with them. I am grateful as well to Prof. Pierpaolo Degano for coordinating and for all the support that he has given me throughout my academic life in Pisa. I thank the members of my dissertation committee for their contribution and their good-natured support, I also thank the other members of department of computer science, university of Pisa, for all good memories, help and all the things they taught me. I also thank Robert Tarjan for his time, support and encouragement to prove their conjecture on the number of rotations in AVL trees. Last but not least, I sincerely and wholeheartedly express my gratitude to all my family mem- bers specially my parents and my wonderful wife for their patience and support. vi Contents 1 Introduction 1 1.1 Memory Hierarchy and Memory Models........................1 1.2 Main Results.......................................2 1.3 Other Results on Properties of AVL Trees.......................5 1.4 Thesis Organization and Overview...........................7 2 Background 9 2.1 Trees and Binary Search Trees.............................9 2.1.1 Isomorphism on rooted trees.......................... 10 2.1.2 Positional Trees.................................. 11 2.1.3 Binary Search Trees............................... 13 2.1.4 B-tree, 2-3 Tree and (a,b)-trees......................... 23 2.1.5 Tree Representation............................... 24 2.1.6 Tree Traversal.................................. 24 2.2 External-Memory & Cache-Oblivious Memory Models................ 25 2.2.1 External-Memory Model............................. 26 2.2.2 Cache-Oblivious Memory Model........................ 27 2.3 Data Structures for External-Memory & Cache-Oblivious Memory Models..... 28 2.4 Exhaustive Generation of Trees with Bounded Degree................ 32 2.4.1 Generation Preliminaries............................ 33 2.4.2 Trees with Bounded Degree........................... 37 2.4.3 Related Works to Trees with Bounded Degree................. 39 2.5 Summary......................................... 39 3 Core Partitioning Scheme 41 3.1 Core Partitioning Preliminaries............................. 42 3.2 Core Partitioning Scheme................................ 44 3.2.1 Core Partitioning................................. 44 3.2.2 Memory Management.............................. 47 3.2.3 Maintaining the Core Partition......................... 47 3.3 Applications........................................ 49 3.3.1 External-Memory Search Trees......................... 49 3.3.2 Cache-Oblivious Search Trees.......................... 50 3.4 Case Study 1: Weight-Balanced Trees......................... 55 3.4.1 Cores in Weight-Balanced Trees........................ 56 3.4.2 Amortized Analysis for Repartitioning..................... 58 3.5 Case Study 2: AVL Trees................................ 59 3.5.1 Cores in AVL Trees............................... 59 3.5.2 Amortized Analysis for Repartitioning..................... 63 3.6 Summary......................................... 65 viii CONTENTS 4 Core Partitioning Directly on Plain Binary Trees 67 4.1 Preliminaries and Notation............................... 68 4.2 Definition of COG-Tree................................. 69 4.3 Memory Management.................................. 78 4.4 Maintaining a COG-Tree................................ 78 4.4.1 Deletions..................................... 79 4.4.2 Insertions..................................... 79 4.5 Applications........................................ 80 4.5.1 External-Memory Search Trees......................... 81 4.5.2 Cache-Oblivious Search Trees.......................... 81 4.6 Amortized Analysis.................................... 82 4.7 Summary......................................... 84 5 Other Properties of AVL Trees 85 5.1 GAP............................................ 85 5.1.1 General Properties of Gaps........................... 86 5.1.2 Gaps in Insertions and Deletions........................ 88 5.2 Amortized Rotation Cost in AVL Trees........................ 92 5.2.1 Expensive AVL Trees.............................. 95 5.3 Summary......................................... 97 6 Generation of Trees with Bounded Degree 99 6.1 The Encoding Schema.................................. 100 6.2 The Generation Algorithm................................ 103 6.3 Ranking and Unranking Algorithms.......................... 107 6.4 Summary......................................... 113 7 Conclusions and Discussion 115 Bibliography 119 List of Figures 2.1 An example of the heights and the levels of the nodes in a given tree......... 10 2.2 An embedding of an ordered rooted tree in the plane on a set of 11 nodes (4 internal nodes and 7 leaves) with root labeled by `x'....................... 11 2.3 An example of a 3-regular tree.............................. 12 2.4 In a BST, for every node with key x, the keys in the left (right) subtree are less (greater) than x...................................... 13 2.5 An example of AVL tree................................. 15 2.6 Right rotation at node x. Triangles denote subtrees. The inverse operation is a left rotation at y........................................ 15 2.7 A Fibonacci tree of height 5 in the left side and one of its isomorphisms in the right side............................................. 16 2.8 Single and double rotations in a red-black tree..................... 18 2.9 Recoloring in a red-black tree............................... 19 2.10 BB[α]-tree for α = 2=7 while it is not for α = 1=3................... 20 2.11 An example of Randomized Search Tree, in this picture the numbers are priorities and the alphabets are the keys.............................. 22 2.12 An inorder traversal algorithm for binary trees.................... 25 2.13 A postorder traversal algorithm for binary trees.................... 25 2.14 A preorder traversal algorithm for binary trees..................... 25 2.15 The external-memory model............................... 27 2.16 Left: C3H8 propane, middle and right: C4H10 butanes................ 38 2.17 A T ∆ tree with 12 nodes (for any ∆ ≥ 4)........................ 38 3.1 Decomposition of a binary search tree into its cores.................. 45 3.2 Left: when w is higher than v, so u = w. Right: when w is lower than v, so u = v. 48 3.3 Subtree τ with its core C