GENERATING THE FIBONACCI CHAIN IN O(log n) SPACE AND O(n) TIME J. Patera
|
|
|
- Chloe Robbins
- 10 years ago
- Views:
Transcription
1 ˆ ˆŠ Œ ˆ ˆ Œ ƒ Ÿ Š GENERATING THE FIBONACCI CHAIN IN O(log n) SPACE AND O(n) TIME J. Patera Department of Mathematics, Faculty of Nuclear Science and Physical Engineering, Czech Technical University, Praha, Czech Republic On the example of the Fibonacci chain we show how to efˇciently generate inˇnite words deˇned by substitutions. We introduce substitution trees and we present an algorithm that uses them to generate suchinˇnite words. We use a stack to generate the words in a completely different manner than in traditional breadth-ˇrst tree traversals. We show that the algorithm has O(log n) space complexity and O(n) time complexity, where n is the length of the generated word. The aperiodic Fibonacci chain is used for construction of aperiodic pseudorandom number generators. INTRODUCTION In this paper we study a special kind of trees that we call substitution trees. We use them to represent iterations of substitutions on ˇnite alphabets. The speciˇty of substitution trees is that, although being inˇnite, they contain only a very small ˇnite number of different two-level subtrees. We use substitution trees for efˇcient iteration of the substitutions, which they represent, to generate a possibly inˇnite word. The concept of substitution trees can be applied to any substitution, but we will illustrate it on the Fibonacci substitution and the Fibonacci chain. We further introduce a new algorithm for breadth-ˇrst tree traversal that perfectly suits substitution trees. The general breadth-ˇrst (also called levelorder) traversal, as described, for example, by Knuth[3], uses a queue to store up to one entire level of the tree, i. e., the queue size is O(n), ifn is the number of nodes on the given level. Our new algorithm requires only a stack of size O(log n), i. e., its size is equal to the tree depth. We also analyze the time complexity of the new traversal. We show that the time needed to traverse from a node to the adjacent node on the same level is not constant, but its average value is bounded. Thus n nodes can be traversed in O(n) time. [email protected]ˇ.cvut.cz
2 226 PATERA J. The results of this paper can be used, for example, for exact generation of special aperiodic self-similar point sets, called cut and project sequences [4, 5]. These sequences are essential for the design of a new type of aperiodic pseudo-random number generators (APRNG), introduced in [1] and studied, for example, in [2]. 1. PRELIMINARIES A substitution θ is a mapping of a ˇnite alphabet A into the set A of ˇnite words in the letters of A suchthat θ(a) is nonempty for any a A. In particular, the Fibonacci substitution is deˇned on the alphabet A = {A, B} with substitution rules θ(a) =ABA and θ(b) =AB. A sequence of j-thiterations of the substitution on the letter A is a sequence of words θ j (A) of increasing lengthsuchthat θ j+1 (A) =θ j (A)ω j for some words ω j. The inˇnite word θ (A) =ABAABABA..., towhich θ j (A) converges, is invariant withrespect to this substitution and is called the Fibonacci chain. w for some word w denotes the number of letters in w, we call it the length of w. Further details on substitutions can be found, e. g., in [6], and particularly on the Fibonacci substitution in [4]. The Fibonacci numbers will be very often used in this paper, they are deˇned by the following recurrence: Solving this recurrence, one obtains F j = F j 1 + F j 2, F 0 =0, F 1 =1. (1) F j = 5 1 (τ j τ j ) (2) and τ j = F j τ + F j 1, where τ = 1 2 (1 + 5) and τ = 1 2 (1 5). Let us recall that from (2) it follows that F j = O(τ j ). On the other hand, if f(k) is increasing for k N and f(f j )=O(j), thenf(j) =O(log j). Proposition. Let θ be the Fibonacci substitution. The lengths of words θ j (A) are θ j (A) = F 2j+2 for all non negative integers j. Proof. Let p A (j) and p B (j) denote the number of letters A and B, respectively, in θ j (A). Clearly, p A (j+1) = 2p A (j)+p B (j), p B (j+1) = p A (j)+p B (j), p A (0) = 1, andp B (0) = 0. It can be shown easily by induction, that p A (j +1) = F 2j+1 and p B (j) =F 2j and thus θ j (A) = F 2j+1 + F 2j = F 2j+2.
3 GENERATING THE FIBONACCI CHAIN IN O(log n) SPACE 227 This proposition gives the number of iterations of θ that are needed to generate n elements. Indeed, it can be used to ˇnd j suchthat F 2(j 1)+2 <n F 2j+2. In Sec. 2, we present an algorithm requiring just j 1 memory cells (besides the memory needed for the substitution itself) to generate the ˇrst n elements of the sequence. 2. SUBSTITUTION TREES In this section we introduce an efˇcient way of representing iterations of substitutions, the substitution trees, and we show how to use them to generate the Fibonacci chain. Let t n,forn 0, bethen-th letter of the Fibonacci chain, with t 0 = A being the starting letter. To the Fibonacci substitution, a substitution tree can be assigned. It is a tree withnodes and edges bothlabeled. The root node is labeled as A (A is the starting letter of the substitution) and every other node is labeled either as A or B. Every A node has θ(a) =3children nodes, labeled A, B, A, respectively, in the given order according to the word θ(a) =ABA, and every B node has θ(b) =2children nodes, labeled according to θ(b) =AB (see Fig. 1). The edge connecting a node withits i-thchild node is labeled withthe index i. We call the given node with all its descendant nodes a subtree. The subtree rooting at any A node is isomorphic to the entire tree. Therefore the j-thlevel of the tree coincides with the beginning of the (j +1)-thlevel, i. e., θ j+1 (A) =θ j (A)ω j for certain word ω j, and thus θ j+1 (A) =Aω 0 ω 1 ω 2...ω j. (3) Fig. 1. The ˇrst 3 levels of the substitution tree for the Fibonacci substitution θ(a) = ABA, θ(b) =AB. Th e j-th level of the tree corresponds to the j-thiteration of θ. In generation of the j-thiteration of θ, the letters to the left of the thick line are skipped as they correspond to the already generated (j 1)-thlevel. To ease the notation, we write A n or B n if the n-thgenerated letter is A or B, respectively
4 228 PATERA J. Letters t 0,...,t n can be generated either by traversing a single sufˇciently long level θ j (A) from its left end, or using (3) by traversing the right parts of the levels of the tree, given by the words ω j, starting at the ˇrst level. Figure 1 shows the ˇrst three levels of the substitution tree for the Fibonacci substitution. The subscripts of nodes denote the order in which the letters t n are generated. We have described the idea of using substitution trees for generation. We further discuss technical issues of an implementation of the given algorithm. Eachof the substitution rules θ(a) and θ(b) appears repeatedly in many nodes, and therefore it is impractical to keep the entire tree in the computer memory or even to construct a long part of it, especially if the required length n of the Fibonacci chain is not known in advance (and thus the depth of the used part of the tree). The only data used for generation is a static set of substitution rules and a stack, as described below. The set of rules does not change within the generation although, the tree is being repeatedly extended by a new level. On the other hand, the stack grows by one item whenever a new tree level is started. The way the substitution tree is traversed is the so-called breadth-ˇrst traversal which traditionally needs a queue to be performed. Instead of a queue, we use a stack in a completely different way than the stack is used in traditional breadth-ˇrst traversals [3]. The position of every node ν in a tree is uniquely determined by the path from ν to the root. The path is given by the sequence of all ancestors of ν and edges it passes through. The stack is here used to store the reversed sequence of nodes and edges from the root to the parent of the parent of ν. Thus the nodes on the two deepest levels are never stored in the stack. Eachitem of the stack consists of two parts (letter, index): the node label and the label of the edge that leads to the node following in the path. We use the substitution rules represented by the nodes in the (d 1)-thlevel to generate the subordinate letters in the d-th level at once, without use of the stack. For example, when the letters t 3 = A and t 4 = B are being generated (refer to Fig. 1), the tree has two levels and the stack consists just of one item: (A, 2), because t 3 and t 4 are generated by simple application of θ(b) =AB rooting at t 1 = B in the ˇrst level; in this case (A, 2) means the second child node of t 0 = A. Whereas when the third level is started and the letters t 8 =A, t 9 =B, andt 10 =A are generated, the stack has two items: (A, 2) and (B,1), representing the second child node of A 0 and the ˇrst child of B 1. The traversing algorithm works as follows. Since generally there are no direct links between adjacent nodes (i. e., through their common parent node) on any level, it is occasionally necessary to make a detour through a certain number of upper levels: to go up in the tree and then to go down again. For example, in Fig.1togofromB 12 to A 13 we must go back to the root. When the generator enters, say, the i-thsubtree of a node ν, i. e., it goes down from ν to its subtree, then it pushes the node name ν and the index i to the stack. When all subtrees
5 GENERATING THE FIBONACCI CHAIN IN O(log n) SPACE 229 of ν of the given depth are traversed, it is necessary to pop the parent node and edge (a, i) from the stack. The popping is then repeated as long as i = θ(a) for the newly popped values of a and i. This condition checks whether the entire subtree of a was already traversed. After that the pair (a, i +1) is pushed and the new a is deˇned as the letter θ(a) i+1. Finally it is necessary to go down the tree to reach the original level where the popping started. Every level stepped down is represented by pushing the pair (a, 1) and deˇning new a as θ(a) 1. If, in the above popping, the stack got empty and i = θ(a) still holds, then it means that the entire tree level was traversed, that a new one must be started, and that a new stack, with one more level than before, must be built. The stack is built in such a way that the ˇrst subtree of the tree root is skipped, i. e., the built path is the closest one to the right of the thick line in Fig. 1. The generation algorithm is given formally in Algorithm 1. It generates the sequence (t i ) N i=0,wheret 0 is the given starting letter A. Th e used stack stores pairs (letter, index). The variable l counts the number of stack items that were popped between generations of two consecutive letters and are thus necessary to be pushed back. If an entire level gets traversed, l is incremented. It signals that a deeper stack needs to be built because a new level is about to be started. stack := empty; a := t 0 ; n := 1; i := 2; while (n N) do while (i θ(a) ) do t n := θ(a) i ; n := n+1; i := i+1; enddo; l := 0; while (not stack.isempty) and (i > θ(a) ) do stack.pop(a, i); l := l +1; i := i +1; enddo; if (stack.isempty) then a := t 0 ; i := 2; l := l +1; endif; repeat stack.push(a, i); a := θ(a) i ; i := 1; l := l 1; until (l =0); enddo; Algorithm 1: Generating N letters of the Fibonacci chain using its substitution tree.
6 230 PATERA J. The fact that after generating n letters of the chain the stack contains as many pairs (letter, index) as many levels the corresponding generated tree has, leads us to the following theorem. Theorem 1. The space complexityof Algorithm 1 for generation of n letters of the Fibonacci chain is O(log n). 3. TIME COMPLEXITY OF SUBSTITUTION TREES Performance of every algorithm should be studied from different points of view. In this section we examine the time characteristics of traversing substitution trees. We look at the average, best, and worst time needed for generation of a single letter. The most time-consuming operations in the tree traversing are the stack operations. We will further refer to a pair of pushing and popping as to a single (stack) operation, assuming that the letter production time itself is neglectable. The average number of operations per generated letter M(n) is the ratio of the total number of operations for all letters N (n) and the number of letters n. In the analysis of M(n), we will ˇrst consider the case n = F 2j+2, i. e., that an entire level is generated (see Proposition). When the right part ω j of the j-th level, i. e., the letters t i with F 2j <i F 2j+2, is being generated, every edge entering any node corresponding to t i, 1 i F 2j, is pushed to and popped from the stack, and it is done exactly once. Therefore the generation of the letters t i, F 2j <i F 2j+2 requires N j := F 2j operations. In total, summing for all ω j, generation of the sequence (t i ) F2j+2 i=1 requires N (F 2j+2 )= j N k = k=1 j F 2k <F 1 + k=1 j F 2k = F 2j+1 operations. Obviously, N (n) is a nondecreasing function satisfying N (F 2j+2 ) F 2j+1. Let now n be an arbitrary positive integer. We have F 2j n F 2j+2 for some j and therefore the average number of operations per letter is k=1 M(n) = N (n) n < N (F 2j+2) F 2j < 2τ N (F 2j+2) F 2j+1 < 2τ F 2j+1 F 2j+1 < 2τ. We used the estimate F j+1 /F j < 2τ following from (2); in limit, the ratio F j+1 /F j is τ. These considerations lead us to the following theorem. Theorem 2. The Fibonacci chain can be generated using the substitution tree in O(n) time, where n is the length of the generated word.
7 GENERATING THE FIBONACCI CHAIN IN O(log n) SPACE 231 We see that in average the number of operations per letter is uniformly bounded by a constant, independent of n. However, if (t i ) n i=0 has already been generated, the upper bound of number of operations needed to determine t n+1 is a function of n. When traversing a substitution tree, it is usually necessary to go up through the tree and then descend. For example, generating t 13 from t 12 requires going up to the tree root. The maximal number of operations per single letter is therefore equal to the tree depth, i. e., is proportional to log n. On the other hand, the number of operations is 0 when t n and t n+1 are two direct children nodes of the same node, such as t 13 and t SKIPPING n LETTERS IN THE FIBONACCI CHAIN Algorithm 1 in Sec. 2 generates the Fibonacci chain from the beginning. Some applications may require a sequence starting at an arbitrary n-thletter, for example the APRNG needs the ability of starting generation from any seedpoint. This can be done naively by brute-force generating and discarding all the unnecessary letters. In this section we provide an efˇcient algorithm for starting generation from any n-th letter. At the end of the section we generalize it to the skipping of arbitrary n letters at any position. Starting generation from the n-thletter is equivalent to building a stack simulating generation of the previous n 1 letters. Fig. 2. The process of building a stack for the generation starting from an n-thletter. It is illustrated on the letter t 17 of the substitution tree for the Fibonacci substitution. The nodes α, β, γ, δ, andε must be traversed before the letter t 17 is reached In the substitution tree for the Fibonacci substitution, the number of letters on any level of any subtree can always be determined. Let l : {A, B} N N be deˇned as follows: { F l(a, j) := 2j+2, for a = A F 2j+1, for a = B.
8 232 PATERA J. According to Proposition and its generalization for letter B, l(a, j) gives the number of letters on the j-thlevel of the tree for θ j (a), i.e.,l(a, j) = θ j (a). Let us assume that we want to skip n letters, i. e., to start generation from the (n+1)-th letter. We determine the level on which the (n+1)-thletter resides. We then build the path to it from the tree root and we store the path in the stack. The resulting stack is the desired stack. We illustrate the stack building on n =17. The algorithm has three parts (refer to Fig. 2): Determine the tree depth d. Find d suchthat θ d 1 (A) n< θ d (A), then the tree will have d levels and the constructed stack will have d 1 items. In our case, d =3since (8 =) F n<f (= 21). Build the stack by a single deterministic walk down the tree from the top to the right bottom, starting at the ˇrst node of the ˇrst level. In every node ν determine, using the l function, whether the ˇnite subtree rooting at this node should be skipped entirely or if it contains the (n+1)-thletter. If it does contain the letter, the path continues in this subtree and therefore we push the position of this descendant node (i. e., its parent ν and the edge connecting them) into the stack and we enter the subtree on the left-most node of its ˇrst level. If it does not contain the letter, we repeat the procedure on the right sibling node of ν (there always is such a node, this follows from the way the path is determined). The procedure is repeated recursively until the stack has d 1 items. We always start on the left-most node of the ˇrst level. In our example, the left-most node is denoted by α. α contains l(a, 2) = 8 letters which is less than 17. Therefore we skip it and proceed to the subtree root β. It contains l(b,2) = 5 letters which is less than n l(a, 2) = 17 8=9, therefore we also skip it. The subtree γ contains l(a, 2) = 8 letters. It is more than 9 5=4, therefore the path continues in this subtree. We push the pair (A, 3), the position of γ, into the stack and we proceed to the subtree δ. It contains l(a, 1) = 3 letters, less than 4, so we proceed to ε. This subtree contains l(b,1) = 2 letters, more than 4 3=1, therefore the path continues in this subtree. We push the pair (A, 2) into the stack, because we are going down to the subtree ε. The stack now contains d 1 =2items, therefore we reached the bottom of the tree and the stack is (A, 3), (A, 2). Finally, we determine the starting position in the substitution rule we found by skipping the remaining letters from the beginning. In our example, the ˇrst letter to be generated is θ(b) 2 because n 8 5 3=1. The formal version of this informal description is shown in Algorithm 2. The lenghts of words θ j (a) can be simply calculated by l(a, j). The algorithm just given can be generalized easily to skipping of arbitrary n letters from arbitrary position in the sequence. Indeed, instead of starting with empty stack and descending in the tree, we can use an already existing stack and start by climbing up the tree, using a procedure similar to the one mentioned in the second item of the above given description. After a certain number of
9 GENERATING THE FIBONACCI CHAIN IN O(log n) SPACE 233 steps, the direction of traversing will change and we will start going down toward the deepest level. It may happen that it is required to skip more letters than the number of letters remaining on the deepest level is. In such a case, a slight modiˇcation of Algorithm 2 can be applied to the remaining letters that did not ˇt in the previous level. The modiˇcation consists in skipping the ˇrst left subtree α of the tree root. Theorem 3. Skipping n letters in the Fibonacci chain requires O(log n) operations. Stack := empty; a := t 0 ; if (n > θ(a) ) then Find d suchthat θ d 1 (a) n< θ d (a) ; repeat i := 1; d := d 1; while ( θ d (θ(a) i ) n) do n := n θ d (θ(a) i ) ; i := i +1; enddo; stack.push(a, i); a := θ(a) i ; until (d =1); endif; Start generating with θ(a) n+1. Algorithm 2: Skipping n letters and creating the stack. CONCLUSION The concept of substitution trees and their traversals can be, without any modiˇcations, applied to an arbitrary substitution on any ˇnite alphabet. The cut and project sequences [5] used in the APRNG design [1] have generally much larger alphabets than just two letters. In any case, the O(n) time and O(log n) space complexity of generation is preserved. For skipping n letters, the ability to determine the exact number of letters on any level of any tree is essential. In general, multiplications of matrices of substitutions [4] may be needed rather than a simple calculation of a recurrent sequence like (1). Besides the matrix operations, the algorithm also has O(log n) time complexity. Skipping n letters does not necessarily require building the entire O(log n) stack. In cases when only few points are to be generated (compared to the number
10 234 PATERA J. of letters to be skipped), a certain number of the top items will never be used. Indeed, it may happen that only a minor part of a single tree level is to be used without the need of going too far towards the tree root. If the upper bound on the number of letters to be generated is known in advance, Algorithm 2 can be modiˇed in such a way that the stack items corresponding to the upper tree levels will not be pushed into the stack. If, for example, at most m letters starting at the letter t n are about to be generated, the stack. push operation in Algorithm 2 can be ignored (i. e., not performed) as long as t n and t n+m are in the same subtree of the node currently traversed in the while loop of Algorithm 2. Let us conclude withsome numbers. In our most efˇcient implementation of the presented tree traversal, a single stack item consists just of one memory pointer. On a 32-bit computer, a 1 KB stack can be used to generate F letters of the Fibonacci chain, i. e., elements of a binary aperiodic sequence usable by the APRNG. Acknowledgements. The author would like to thank L.-S. Guimond, Z. Masakova, and E. Pelantova for their stimulating discussions and many suggestions to the manuscript. This work was supported by the Bell Canada University Laboratory, by the NATO Collaborative Research Grant CRG and by the grant FRVS 1927/2001 of the Czech Ministry of Education. The author is also grateful for the hospitality of the Centre de Recherches Mathematiques in Montreal (Quebec, Canada), where part of the work was done. REFERENCES 1. Guimond L.-S., Patera J. Combining Random Number Generators Using Cut and Project Sequences // Czech. J. Phys V. 26. P. 305Ä Guimond L.-S., Patera J. Statistics and Implementation of Aperiodic Pseudorandom Number Generators. Preprint Subm. to Appl. Num. Math.. 3. Knuth D. E. The Art of Computer Programming: Fundamental Algorithms. 3rd ed. Addison- Wesley, V Luck J. M. et al. The Nature of the Atomic Surfaces of Quasiperiodic Self-Similar Structures // J. Phys. A: Math. Gen V. 26. P. 1951Ä Masakova Z.,PateraJir, Pelantova E.Substitution Rules for Aperiodic Sequences of the Cut and Project Type // J. Phys. A: Math. Gen V. 33. P. 8867Ä Queffelec M. Substitution Dynamical Systems: Spectral Analysis. Berlin: Springer, 1987.
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
The Goldberg Rao Algorithm for the Maximum Flow Problem
The Goldberg Rao Algorithm for the Maximum Flow Problem COS 528 class notes October 18, 2006 Scribe: Dávid Papp Main idea: use of the blocking flow paradigm to achieve essentially O(min{m 2/3, n 1/2 }
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
Full and Complete Binary Trees
Full and Complete Binary Trees Binary Tree Theorems 1 Here are two important types of binary trees. Note that the definitions, while similar, are logically independent. Definition: a binary tree T is full
ER E P M A S S I CONSTRUCTING A BINARY TREE EFFICIENTLYFROM ITS TRAVERSALS DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF TAMPERE REPORT A-1998-5
S I N S UN I ER E P S I T VER M A TA S CONSTRUCTING A BINARY TREE EFFICIENTLYFROM ITS TRAVERSALS DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF TAMPERE REPORT A-1998-5 UNIVERSITY OF TAMPERE DEPARTMENT OF
The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge,
The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge, cheapest first, we had to determine whether its two endpoints
INDISTINGUISHABILITY OF ABSOLUTELY CONTINUOUS AND SINGULAR DISTRIBUTIONS
INDISTINGUISHABILITY OF ABSOLUTELY CONTINUOUS AND SINGULAR DISTRIBUTIONS STEVEN P. LALLEY AND ANDREW NOBEL Abstract. It is shown that there are no consistent decision rules for the hypothesis testing problem
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
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
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
Mathematical Induction. Lecture 10-11
Mathematical Induction Lecture 10-11 Menu Mathematical Induction Strong Induction Recursive Definitions Structural Induction Climbing an Infinite Ladder Suppose we have an infinite ladder: 1. We can reach
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
Efficiency of algorithms. Algorithms. Efficiency of algorithms. Binary search and linear search. Best, worst and average case.
Algorithms Efficiency of algorithms Computational resources: time and space Best, worst and average case performance How to compare algorithms: machine-independent measure of efficiency Growth rate Complexity
s-convexity, model sets and their relation
s-convexity, model sets and their relation Zuzana Masáková Jiří Patera Edita Pelantová CRM-2639 November 1999 Department of Mathematics, Faculty of Nuclear Science and Physical Engineering, Czech Technical
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 [email protected] 2005 2009 Glenn G. Chappell
Algorithms Chapter 12 Binary Search Trees
Algorithms Chapter 1 Binary Search Trees Outline Assistant Professor: Ching Chi Lin 林 清 池 助 理 教 授 [email protected] Department of Computer Science and Engineering National Taiwan Ocean University
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
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
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:
Graphs without proper subgraphs of minimum degree 3 and short cycles
Graphs without proper subgraphs of minimum degree 3 and short cycles Lothar Narins, Alexey Pokrovskiy, Tibor Szabó Department of Mathematics, Freie Universität, Berlin, Germany. August 22, 2014 Abstract
1/1 7/4 2/2 12/7 10/30 12/25
Binary Heaps A binary heap is dened to be a binary tree with a key in each node such that: 1. All leaves are on, at most, two adjacent levels. 2. All leaves on the lowest level occur to the left, and all
GRAPH THEORY LECTURE 4: TREES
GRAPH THEORY LECTURE 4: TREES Abstract. 3.1 presents some standard characterizations and properties of trees. 3.2 presents several different types of trees. 3.7 develops a counting method based on a bijection
R u t c o r Research R e p o r t. A Method to Schedule Both Transportation and Production at the Same Time in a Special FMS.
R u t c o r Research R e p o r t A Method to Schedule Both Transportation and Production at the Same Time in a Special FMS Navid Hashemian a Béla Vizvári b RRR 3-2011, February 21, 2011 RUTCOR Rutgers
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
Lecture 1: Course overview, circuits, and formulas
Lecture 1: Course overview, circuits, and formulas Topics in Complexity Theory and Pseudorandomness (Spring 2013) Rutgers University Swastik Kopparty Scribes: John Kim, Ben Lund 1 Course Information Swastik
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
Load Balancing. Load Balancing 1 / 24
Load Balancing Backtracking, branch & bound and alpha-beta pruning: how to assign work to idle processes without much communication? Additionally for alpha-beta pruning: implementing the young-brothers-wait
A REMARK ON ALMOST MOORE DIGRAPHS OF DEGREE THREE. 1. Introduction and Preliminaries
Acta Math. Univ. Comenianae Vol. LXVI, 2(1997), pp. 285 291 285 A REMARK ON ALMOST MOORE DIGRAPHS OF DEGREE THREE E. T. BASKORO, M. MILLER and J. ŠIRÁŇ Abstract. It is well known that Moore digraphs do
Analysis of Algorithms I: Optimal Binary Search Trees
Analysis of Algorithms I: Optimal Binary Search Trees Xi Chen Columbia University Given a set of n keys K = {k 1,..., k n } in sorted order: k 1 < k 2 < < k n we wish to build an optimal binary search
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
Rotation Operation for Binary Search Trees Idea:
Rotation Operation for Binary Search Trees Idea: Change a few pointers at a particular place in the tree so that one subtree becomes less deep in exchange for another one becoming deeper. A sequence of
Recursive Algorithms. Recursion. Motivating Example Factorial Recall the factorial function. { 1 if n = 1 n! = n (n 1)! if n > 1
Recursion Slides by Christopher M Bourke Instructor: Berthe Y Choueiry Fall 007 Computer Science & Engineering 35 Introduction to Discrete Mathematics Sections 71-7 of Rosen cse35@cseunledu Recursive Algorithms
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:
Lecture 3: Finding integer solutions to systems of linear equations
Lecture 3: Finding integer solutions to systems of linear equations Algorithmic Number Theory (Fall 2014) Rutgers University Swastik Kopparty Scribe: Abhishek Bhrushundi 1 Overview The goal of this lecture
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
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
A Practical Scheme for Wireless Network Operation
A Practical Scheme for Wireless Network Operation Radhika Gowaikar, Amir F. Dana, Babak Hassibi, Michelle Effros June 21, 2004 Abstract In many problems in wireline networks, it is known that achieving
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
Measuring the Performance of an Agent
25 Measuring the Performance of an Agent The rational agent that we are aiming at should be successful in the task it is performing To assess the success we need to have a performance measure What is rational
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
arxiv:1112.0829v1 [math.pr] 5 Dec 2011
How Not to Win a Million Dollars: A Counterexample to a Conjecture of L. Breiman Thomas P. Hayes arxiv:1112.0829v1 [math.pr] 5 Dec 2011 Abstract Consider a gambling game in which we are allowed to repeatedly
The LCA Problem Revisited
The LA Problem Revisited Michael A. Bender Martín Farach-olton SUNY Stony Brook Rutgers University May 16, 2000 Abstract We present a very simple algorithm for the Least ommon Ancestor problem. We thus
n k=1 k=0 1/k! = e. Example 6.4. The series 1/k 2 converges in R. Indeed, if s n = n then k=1 1/k, then s 2n s n = 1 n + 1 +...
6 Series We call a normed space (X, ) a Banach space provided that every Cauchy sequence (x n ) in X converges. For example, R with the norm = is an example of Banach space. Now let (x n ) be a sequence
Cpt S 223. School of EECS, WSU
Priority Queues (Heaps) 1 Motivation Queues are a standard mechanism for ordering tasks on a first-come, first-served basis However, some tasks may be more important or timely than others (higher priority)
How Asymmetry Helps Load Balancing
How Asymmetry Helps oad Balancing Berthold Vöcking nternational Computer Science nstitute Berkeley, CA 947041198 voecking@icsiberkeleyedu Abstract This paper deals with balls and bins processes related
The following themes form the major topics of this chapter: The terms and concepts related to trees (Section 5.2).
CHAPTER 5 The Tree Data Model There are many situations in which information has a hierarchical or nested structure like that found in family trees or organization charts. The abstraction that models hierarchical
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
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
Offline sorting buffers on Line
Offline sorting buffers on Line Rohit Khandekar 1 and Vinayaka Pandit 2 1 University of Waterloo, ON, Canada. email: [email protected] 2 IBM India Research Lab, New Delhi. email: [email protected]
A Catalogue of the Steiner Triple Systems of Order 19
A Catalogue of the Steiner Triple Systems of Order 19 Petteri Kaski 1, Patric R. J. Östergård 2, Olli Pottonen 2, and Lasse Kiviluoto 3 1 Helsinki Institute for Information Technology HIIT University of
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
Fast nondeterministic recognition of context-free languages using two queues
Fast nondeterministic recognition of context-free languages using two queues Burton Rosenberg University of Miami Abstract We show how to accept a context-free language nondeterministically in O( n log
Hash-based Digital Signature Schemes
Hash-based Digital Signature Schemes Johannes Buchmann Erik Dahmen Michael Szydlo October 29, 2008 Contents 1 Introduction 2 2 Hash based one-time signature schemes 3 2.1 Lamport Diffie one-time signature
CHAPTER 5. Number Theory. 1. Integers and Division. Discussion
CHAPTER 5 Number Theory 1. Integers and Division 1.1. Divisibility. Definition 1.1.1. Given two integers a and b we say a divides b if there is an integer c such that b = ac. If a divides b, we write a
Generating models of a matched formula with a polynomial delay
Generating models of a matched formula with a polynomial delay Petr Savicky Institute of Computer Science, Academy of Sciences of Czech Republic, Pod Vodárenskou Věží 2, 182 07 Praha 8, Czech Republic
Lecture 4: BK inequality 27th August and 6th September, 2007
CSL866: Percolation and Random Graphs IIT Delhi Amitabha Bagchi Scribe: Arindam Pal Lecture 4: BK inequality 27th August and 6th September, 2007 4. Preliminaries The FKG inequality allows us to lower bound
University of Ostrava. Reasoning in Description Logic with Semantic Tableau Binary Trees
University of Ostrava Institute for Research and Applications of Fuzzy Modeling Reasoning in Description Logic with Semantic Tableau Binary Trees Alena Lukasová Research report No. 63 2005 Submitted/to
Lecture 4 Online and streaming algorithms for clustering
CSE 291: Geometric algorithms Spring 2013 Lecture 4 Online and streaming algorithms for clustering 4.1 On-line k-clustering To the extent that clustering takes place in the brain, it happens in an on-line
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
CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015
CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis Linda Shapiro Today Registration should be done. Homework 1 due 11:59 pm next Wednesday, January 14 Review math essential
Degree Hypergroupoids Associated with Hypergraphs
Filomat 8:1 (014), 119 19 DOI 10.98/FIL1401119F Published by Faculty of Sciences and Mathematics, University of Niš, Serbia Available at: http://www.pmf.ni.ac.rs/filomat Degree Hypergroupoids Associated
Math 55: Discrete Mathematics
Math 55: Discrete Mathematics UC Berkeley, Spring 2012 Homework # 9, due Wednesday, April 11 8.1.5 How many ways are there to pay a bill of 17 pesos using a currency with coins of values of 1 peso, 2 pesos,
arxiv:cs/0605141v1 [cs.dc] 30 May 2006
General Compact Labeling Schemes for Dynamic Trees Amos Korman arxiv:cs/0605141v1 [cs.dc] 30 May 2006 February 1, 2008 Abstract Let F be a function on pairs of vertices. An F- labeling scheme is composed
Discrete Mathematics & Mathematical Reasoning Chapter 10: Graphs
Discrete Mathematics & Mathematical Reasoning Chapter 10: Graphs Kousha Etessami U. of Edinburgh, UK Kousha Etessami (U. of Edinburgh, UK) Discrete Mathematics (Chapter 6) 1 / 13 Overview Graphs and Graph
Lecture 2: Universality
CS 710: Complexity Theory 1/21/2010 Lecture 2: Universality Instructor: Dieter van Melkebeek Scribe: Tyson Williams In this lecture, we introduce the notion of a universal machine, develop efficient universal
Sample Questions Csci 1112 A. Bellaachia
Sample Questions Csci 1112 A. Bellaachia Important Series : o S( N) 1 2 N N i N(1 N) / 2 i 1 o Sum of squares: N 2 N( N 1)(2N 1) N i for large N i 1 6 o Sum of exponents: N k 1 k N i for large N and k
6.852: Distributed Algorithms Fall, 2009. Class 2
.8: Distributed Algorithms Fall, 009 Class Today s plan Leader election in a synchronous ring: Lower bound for comparison-based algorithms. Basic computation in general synchronous networks: Leader election
IE 680 Special Topics in Production Systems: Networks, Routing and Logistics*
IE 680 Special Topics in Production Systems: Networks, Routing and Logistics* Rakesh Nagi Department of Industrial Engineering University at Buffalo (SUNY) *Lecture notes from Network Flows by Ahuja, Magnanti
Reducing Clocks in Timed Automata while Preserving Bisimulation
Reducing Clocks in Timed Automata while Preserving Bisimulation Shibashis Guha Chinmay Narayan S. Arun-Kumar Indian Institute of Technology Delhi {shibashis, chinmay, sak}@cse.iitd.ac.in arxiv:1404.6613v2
Sequential Data Structures
Sequential Data Structures In this lecture we introduce the basic data structures for storing sequences of objects. These data structures are based on arrays and linked lists, which you met in first year
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:
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:
Single-Link Failure Detection in All-Optical Networks Using Monitoring Cycles and Paths
Single-Link Failure Detection in All-Optical Networks Using Monitoring Cycles and Paths Satyajeet S. Ahuja, Srinivasan Ramasubramanian, and Marwan Krunz Department of ECE, University of Arizona, Tucson,
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)
Approximation Algorithms
Approximation Algorithms or: How I Learned to Stop Worrying and Deal with NP-Completeness Ong Jit Sheng, Jonathan (A0073924B) March, 2012 Overview Key Results (I) General techniques: Greedy algorithms
A Fast Algorithm For Finding Hamilton Cycles
A Fast Algorithm For Finding Hamilton Cycles by Andrew Chalaturnyk A thesis presented to the University of Manitoba in partial fulfillment of the requirements for the degree of Masters of Science in Computer
a 11 x 1 + a 12 x 2 + + a 1n x n = b 1 a 21 x 1 + a 22 x 2 + + a 2n x n = b 2.
Chapter 1 LINEAR EQUATIONS 1.1 Introduction to linear equations A linear equation in n unknowns x 1, x,, x n is an equation of the form a 1 x 1 + a x + + a n x n = b, where a 1, a,..., a n, b are given
FACTORING POLYNOMIALS IN THE RING OF FORMAL POWER SERIES OVER Z
FACTORING POLYNOMIALS IN THE RING OF FORMAL POWER SERIES OVER Z DANIEL BIRMAJER, JUAN B GIL, AND MICHAEL WEINER Abstract We consider polynomials with integer coefficients and discuss their factorization
(IALC, Chapters 8 and 9) Introduction to Turing s life, Turing machines, universal machines, unsolvable problems.
3130CIT: Theory of Computation Turing machines and undecidability (IALC, Chapters 8 and 9) Introduction to Turing s life, Turing machines, universal machines, unsolvable problems. An undecidable problem
Mathematics for Algorithm and System Analysis
Mathematics for Algorithm and System Analysis for students of computer and computational science Edward A. Bender S. Gill Williamson c Edward A. Bender & S. Gill Williamson 2005. All rights reserved. Preface
Algorithms and Data Structures
Algorithms and Data Structures Part 2: Data Structures PD Dr. rer. nat. habil. Ralf-Peter Mundani Computation in Engineering (CiE) Summer Term 2016 Overview general linked lists stacks queues trees 2 2
8.1 Min Degree Spanning Tree
CS880: Approximations Algorithms Scribe: Siddharth Barman Lecturer: Shuchi Chawla Topic: Min Degree Spanning Tree Date: 02/15/07 In this lecture we give a local search based algorithm for the Min Degree
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
Cost Model: Work, Span and Parallelism. 1 The RAM model for sequential computation:
CSE341T 08/31/2015 Lecture 3 Cost Model: Work, Span and Parallelism In this lecture, we will look at how one analyze a parallel program written using Cilk Plus. When we analyze the cost of an algorithm
Class Overview. CSE 326: Data Structures. Goals. Goals. Data Structures. Goals. Introduction
Class Overview CSE 326: Data Structures Introduction Introduction to many of the basic data structures used in computer software Understand the data structures Analyze the algorithms that use them Know
Scheduling Single Machine Scheduling. Tim Nieberg
Scheduling Single Machine Scheduling Tim Nieberg Single machine models Observation: for non-preemptive problems and regular objectives, a sequence in which the jobs are processed is sufficient to describe
0.1 Phase Estimation Technique
Phase Estimation In this lecture we will describe Kitaev s phase estimation algorithm, and use it to obtain an alternate derivation of a quantum factoring algorithm We will also use this technique to design
COUNTING INDEPENDENT SETS IN SOME CLASSES OF (ALMOST) REGULAR GRAPHS
COUNTING INDEPENDENT SETS IN SOME CLASSES OF (ALMOST) REGULAR GRAPHS Alexander Burstein Department of Mathematics Howard University Washington, DC 259, USA [email protected] Sergey Kitaev Mathematics
Network File Storage with Graceful Performance Degradation
Network File Storage with Graceful Performance Degradation ANXIAO (ANDREW) JIANG California Institute of Technology and JEHOSHUA BRUCK California Institute of Technology A file storage scheme is proposed
LECTURE 4. Last time: Lecture outline
LECTURE 4 Last time: Types of convergence Weak Law of Large Numbers Strong Law of Large Numbers Asymptotic Equipartition Property Lecture outline Stochastic processes Markov chains Entropy rate Random
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: [email protected] M. Moorthi
Class notes Program Analysis course given by Prof. Mooly Sagiv Computer Science Department, Tel Aviv University second lecture 8/3/2007
Constant Propagation Class notes Program Analysis course given by Prof. Mooly Sagiv Computer Science Department, Tel Aviv University second lecture 8/3/2007 Osnat Minz and Mati Shomrat Introduction This
Collatz Sequence. Fibbonacci Sequence. n is even; Recurrence Relation: a n+1 = a n + a n 1.
Fibonacci Roulette In this game you will be constructing a recurrence relation, that is, a sequence of numbers where you find the next number by looking at the previous numbers in the sequence. Your job
The Trip Scheduling Problem
The Trip Scheduling Problem Claudia Archetti Department of Quantitative Methods, University of Brescia Contrada Santa Chiara 50, 25122 Brescia, Italy Martin Savelsbergh School of Industrial and Systems
Analysis of Algorithms, I
Analysis of Algorithms, I CSOR W4231.002 Eleni Drinea Computer Science Department Columbia University Thursday, February 26, 2015 Outline 1 Recap 2 Representing graphs 3 Breadth-first search (BFS) 4 Applications
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
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
Dynamic Programming. Lecture 11. 11.1 Overview. 11.2 Introduction
Lecture 11 Dynamic Programming 11.1 Overview Dynamic Programming is a powerful technique that allows one to solve many different types of problems in time O(n 2 ) or O(n 3 ) for which a naive approach
14.1 Rent-or-buy problem
CS787: Advanced Algorithms Lecture 14: Online algorithms We now shift focus to a different kind of algorithmic problem where we need to perform some optimization without knowing the input in advance. Algorithms
