Efficient Algorithms to Globally Balance a Binary Search Tree
|
|
|
- Evan Lindsey
- 10 years ago
- Views:
Transcription
1 RESEARCH CONTRIBUTIONS Programming Techniques and Data Structures Ellis Horowitz Editor Efficient Algorithms to Globally Balance a Binary Search Tree HSl CHANG and S. SlTHARAMA IYENGAR ABSTRACT: A binary search tree can be globally balanced by readjustment of pointers or with a sorting process in O(n) time, n being the total number of nodes. This paper presents three global balancing algorithms, one of which uses folding with the other two adopting parallel procedures. These algorithms show improvement in time efficiency over some sequential algorithms [1, 2, 7] when applied to large binary search trees. A comparison of various algorithms is presented. 1. INTRODUCTION A binary search tree is organized such that for any node, all keys in the left subtree are smaller and those in the right subtree are greater than the key value of that node. It provides a method of data organization which is both flexible and efficient. The formation of binary trees grown in a random manner may have some branches longer than others. We know a binary tree search will, on the average, require (2(n + 1)/n)H, - 3 (~1.386 log2n) comparisons for a tree with n nodes if the keys are inserted into the tree in random order. Thus, by making extra efforts to maintain a perfectly balanced tree instead of a random tree, we could--provided all keys are looked up with equal probability--expect an average improvement of approximately percent in the search path length [3, 7]. The task of balancing a binary search tree is then to adjust the left and right pointers of all the nodes in the tree so that the search path is optimized; we can attain 1984 ACM /84/ the same effect as a binary search without requiring a sorted list. Algorithms that dynamically restore tree structure to balance during insertion or deletion of nodes have been described by Adelson-Velskii, Landis, and Knuth [3, 6]. However, in this paper, we deal with global algorithms that balance the entire tree at one time. A global tree balancing algorithm generally runs in linear time and consists of two parts: first, a traversal to determine the order of all nodes, then restructuring pointers based on that order. Martin and Ness [7] developed an algorithm that reorganizes a tree with n nodes by repetitively subdividing n by 2 and uses the results as guidance to step through the framework of a perfectly balanced tree, i.e., for each node, the number of nodes in its left subtree and right subtree differ by I at most. An in-order traversal is carried out concurrently to provide relative node positions for the pointer-restructuring procedure which fits them into proper places in the balanced tree structure. In this algorithm, a stack is required to save pointers during traversal. Bentley [1] discusses an algorithm to produce perfectly balanced trees. In this algorithm, nodes are passed as a set or a linked list to the balancing procedure which finds the median element of the set of nodes as root and splits the set into two subsets, each forming a balanced subtree at the next level. This process continues until there are no more elements to split. Another algorithm that needs no extra storage was given by Day [2]. The input tree is required to be rightthreaded with negative backtrack pointers to allow July 1984 Volume 27 Number 7 Communications of the ACM 605
2 Algorithm S: {globally balance a binary search tree through folding l procedure BALANCE(ROOT, LSON, RSON, n): integer ROOT, n; integer array LSON, RSON; integer N, M, ANSL, ANSR; integer array LINK(I:n); ltraverse the original tree and set up LINK} procedure TRAVBIND(T): integer T; {pointer to the next node to be visited} if T = null then return; TRAVBIND(LSON(T)); N ~ N + 7; {count the sequence of visit} LINK(N) ~ T; {store the pointer to the Nth node in the Nth element of LINK 1 TRAVBIND(RSON(T)); {reorganize a tree by partitioning and folding} procedure GROW(LOW, HIGH): integer LOW, HIGH; {MID is the median of a subset bound by LOW and HIGH, TL is the subtree root in the balanced left half-tree, TR is the counterpart of TL in the right half-tree. TL, TR are returned via ANSL, ANSR, respectively} integer MID, TL, TR; case LOW > HIGH Inull branch I : ANSL, ANSR ~ null; LOW = HIGH Ileafl : ANSL ~ LINK(LOW); ANSR ~ LINK(LOW+M); LSON(ANSL), RSON(ANSL) -- null; LSON(ANSR), RSON(ANSR) ~ null; LOW < HIGH {divisible subset}: MID ~ L(LOW + HIGH)/ 2~; TL ~ LINK(MID); TR ~ LINK(MID+M); GROW(LOW, MID-I); Iform left subtree 1 LSON(TL) -- ANSL; LSON(TR) -- ANSR; GROW(MID+7,HIGH); RSON(TL) RSON(TR) ANSL ~ TL; ~ ANSL; ~ ANSR; ANSR ~ TR; if n s 2 then return; N ~ 0; {initialize counter} {form right subtree} TRAVBIND(ROOT); M ~ L(N + I)/ 2~; {folding value} ROOT --LINK(M); {new root} if N = 2 * M then {N is even 1 M -- M + I; {adjust folding value} GROW(I,M--2); {put the node associated with M as a terminal node left to its immediate successorl LSON(LINK(M)), RSON(LINK(M)) -- null; LSON( LINK( M+ 7) ) -- LINK(M) ; else IN is odd} GROW(7,M--7); LSON(ROOT) RSON(ROOT) ~ ANSL; ~ ANSR; FIGURE 1. Algorithm S. 696 Communications of the ACM June 1984 Volume 27 Number 6
3 stackless traversal. A right-skewed tree is formed after traversal and this list-like structure serves as a backbone for the pointer-restructuring procedure which shifts nodes to the left side of the backbone until the subtree path lengths balance, i.e., no path (from root to leaf) differs in length from any other path by more than 1. The produced tree, on the other hand, is not threaded although it can be made a threaded tree with some modification. Martin and Ness's algorithm and Day's algorithm are given as tutorial matter on pages for interested readers. For a broader treatment on balancing binary search trees, see [4-6, 8]. These include the present investigation of the authors. In the next section, we present a new sequential balancing algorithm which also uses partitioning but reduces the number of times of partitioning through folding. Section 3 presents two parallel algorithms as variations of the previous sequential algorithm; and in Section 4, we analyze and compare these algorithms. 2. SEQUENTIAL BALANCING THROUGH FOLDING The node of a tree is assumed to contain the following fields: left subtree pointer LSON, right subtree pointer RSON, and KEY, while ROOT points to the root node of the tree. We first traverse the original tree to determine the order of all n nodes. Array LINK is used to store the ordering information so that the ith element of LINK contains a pointer to the ith node in ascending key order, i.e., KEY(LINK(i - 1)) < KEY(LINK(i)) < KEY(LINK(i + 1)). To reorganize a tree by partitioning the set, following Bentley, we first find the left median, 1 t.(n + 1)/2.3, of the whole set; the node corresponding to that element is to be the root of the new tree. The remaining L(n -- 1)//23 elements with values less than the left median in the left subset and the other r(n - 1)/2"3 elements in the right subset form two partitions. At the next level, we find for each of these two subsets their medians and use the two associated nodes as roots of the two corresponding subtrees as well as LSON and RSON, respectively, of the previous root. This process continues to find the medians at each level, partitions around them, and restructures the tree from top to bottom and from left to right. Further considering the use of LINK, we observe that for trees containing an odd number of nodes, the median of an ordered set also serves as a special value, denoted by M, to let us construct the right half-tree concurrently with the left half-tree because the counterpart elements in the balanced two halves differ by M. If we know the position of an element K in the left half-tree, we can also determine the position of its counterpart element K + M in the right half-tree. So, we only have to partition half of the entire set in order to reorganize the tree structure. We call this procedure folding because it is like something bending over upon itself to form a symmetrical 1 If we have n sorted elements X1... X., the median is (X,~.+1)/2., + X,.~/2.~-1)/2, the left median is X,~n+ll/2.,. and the right median is X~/z.,+~. structure. The value M used in folding is called the folding value. When the total number of nodes is even, we let the right median, n/2 + 1, be the folding value M. The node associated with the left median remains as the root of the tree and the node corresponding to M is placed as the leftmost node in the right half-tree. Algorithm S (Figure 1) is a global balancing algorithm based on this idea. Procedure TRAVBIND traverse the original tree and sets up the auxiliary array LINK. After traversal, procedure GROW recursively partitions and forms the balanced left half-tree with its right-half counterpart built in the same step through folding. Two parameters are used in GROW: LOW, the lower bound, and HIGH, the upper bound for an ordered subset to be relinked in balanced form. The root of a balanced subtree is the left median MID of the subset. Three conditions direct the course of GROW: 1. If LOW > HIGH, we have a null subtree; return a null pointer. 2. If LOW = HIGH, we have a leaf; set up a terminal node and return the node pointer. 3. If LOW < HIGH, we have a divisible subset; do the following: a) find the root T through MID. b) GROW left subtree and return root as LSON of T. c} GROW right subtree and return root as RSON of T. A tree is balanced when the ROOT of the tree, and the LSON and RSON of each node are readjusted. 3. PARALLEL BALANCING Balancing a tree through folding reveals parallelism in the pointer-restructuring procedure. It is possible to divide the set of nodes into subsets and perform reorganizing operations on these parts simultaneously. One way to balance the left half- and right half-tree at the same time is given in Algorithm P1 (Figure 2). In this algorithm, folding is not used and the pointer-restructuring procedure GROW directly resembles Bentley's scheme [1]. Another degree of parallelism exists between traversol and pointer restructuring. If we physically rearrange all nodes in sorted order during traversal, the pointerrestructuring procedure becomes a pointer generator which needs only to know the size of the tree to compute all the LSONs and RSONs for corresponding nodes in the balanced tree structure. A copy of the original tree has to be made for traversal and sorting so that nodes could be regenerated without destroying useful information. Algorithm P2 (Figure 3) describes the way to exploit this parallelism. 4. A COMPARISON OF PERFORMANCE MEASURES Three conditions, when there are 0, 1, or more than 1 element in a subset, dictate the course of the pointerrestructuring procedure in our algorithms. Take Algo- July 1984 Volume 27 Number 7 Communications of the ACM 60?
4 Algorithm PI: }build balanced left half-tree and right half-tree in parallel} procedure BALANCE(ROOT, LSON, RSON, n): integer ROOT, n; integer array LSON, RSON; integer N; integer array LINK(I:n); {traverse the original tree and set up LINK} procedure TRAVBIND(T): integer T; }pointer to the next node to be visited} if T = null then return; TRAVBIND(LSON(T)); N ~ N +I; }count the sequence of visit} LINK(N) ~ T; }store the pointer to the Nth node in the Nth element of LINK} TRAVBIND(RSON(T)); }reorganize a tree by partitioning} procedure GROW(LOW, HIGH): integer LOW, HIGH; }MID is the median of a subset bound by LOW and HIGH, T is the root of the balanced subtree reflected by the subset} integer MID, T; case LOW > HIGH }null branchl:return(null); LOW = HIGH }leaf} : T ~ LINK(LOW); LSON(T), RSON(T) -- null; return(t); LOW < HIGH }divisible subset} : MID -- L(LOW + HIGH)~ 2J; T ~ LINK(MID); co }form left and right subtrees in parallel} LSON(T) ~ GROW(LOW, MID--l); RSON(T) -- GROW(MID+I,HIGH); co return(t); if n ~ 2 then return; N ~ 0; }initialize counter 1 TRAVBIND(ROOT); M ~ ~(N + I)/ 2J; ROOT -- LINK(M); {new root} Ibalance the left and right half-trees in parallel} co LSON(ROOT) ~ GROW(I,M-I); RSON(ROOT) ~ GROW(M+I,N); co FIGURE 2. Algorithm Pl. rithm P1 for example; the number of times each case is executed can be calculated as follows: Let n be the total number of nodes in a set (n _> 3), and let a = ulog2n3, and b = L(2 + 2 ~-1-1)/n.3 Let Ki be the number of times case i is executed in Algorithm P1, i ~ 1, 2, 3. Then, K1 = 12a(t-(n - 2a-*}/2~-lJ} - n - I I -< 2 ~-1 K2 = n - Ka = 2 a-b - K3 1 + Klb Let us suppose that Co is the average time to visit a node during traversal and Ci is the unit time taken to execute case i once. The total balancing time T(n) can 6~ Communications of the ACM July 1984 Volume 27 Number 7
5 be expressed as T(n} = Con + C1K1 + C2K2 + C3K3 = O(n). This expression also applies to Algorithms S and P2. Based upon the above expression, we will do the analyses of Algorithms S, P1, and P2. When balanced through folding as described in Algorithm S, only,n/2j elements have to be partitioned. This tends to decrease Ki's by half and slightly increases C/s. If parallel execution is implemented efficiently, Algorith m P1 should have similar effects as decreasing K/s, in terms of turnaround time, yet without increasing Ci's. The savings in time becomes obvious when n is large. Algorithm' P2 overlaps tra~,ersal and pointer-restructuring, so that the turnaround time should be the greater of the two. Also, C/s tend to be smaller, but more space is required and physical record movement tends to increase Co. The sequential Martin-Ness and Bentley algorithms that recursively partition the set of nodes to fo~m a balanced, binary search tree follow the same partitioning scheme as that in Algorithm S. A higher degree of parallelism and time efficiency is ~ichieved in our algorithms at the expense of increased working space size. By using an array instead of a stack to store the ordering information of the set of nodes, we are able to build halves of the balanced tree simultaneously as in Algorithm S, or construct left subtrees and right subtrees in parallel as in Algorithm P1. By making a copy of the original tree, asdone in Algorithm P2, we Algorithm P2: {build a balanced tree with a parallel sorting process} procedure BALANCE(ROOT, KEY, LSON, RSON, n) : integer ROOT, n; array KEY; integer array LSON, RSON; integer N; integer array KEYCOPY(I:n), LSONCOPY(I:n), RSONCOPY(7:n); {traverse the copy of the original tree and soft keys 1 procedure TRAVSORT(T) : integer T; [pointer to the next node to be visited I if T = null then return; TRAVSORT(LSONCOPY(T)); N ~ N + I; {count the sequence of visit 1 KEY(N) ~ KEYCOPY(T); {put Nth key in Nth position} TRAVSORT(RSONCOPY(T)); {generate pointers for a balanced tree structure} procedure GROW(LOW, HIGH): integer LOW, HIGH; integer MID; {median of a subset bound by LOW and HIGH} CaSe LOW > HIGH {null branch}:return LOW = HIGH {leaf}: (null); LSON(LOW), RSON(LOW) ~ null; return(low); LOW < HIGH {divisible subset}: MID ~ u(low + HIGH)/ 2~; co {form left and right subtrees in parallel} LSON(MID) ~ GROW(LOW, MID-7); RSON(MID) ~ GROW(MID+I,HIGH); co return(mid); if n s 2 then return; {make a copy of the original tree} KEYCOPY -- KEY; LSONCOPY ~ LSON; RSONCOPY ~ RSON; N -- 0; Iinitialize counter} {sort keys and regenerate pointers in parallel} co TRAVSORT(ROOT); ROOT -- GROW(7,n); [new root} co FIGURE 3. Algorithm P2. [uly 1984 Volume 27 Number 7 Communications of the ACM 699
6 Martin and Ness's Algorithm: procedure BALANCE(ROOT, LSON, RSON, n): integer ROOT, n; integer array LSON, RSON; IT holds polnter to node to be visited during traversal, STACK is used to store T, TOP points to the top element of STACK 1 integer T, TOP, ANS; integer array STACK(I:n); {traverse the input tree and return a node pointer in ascending key order via ANSI procedure TRAVNEXT: began if T ~ null then TOP -- TOP + I; STACK(TOP) ~ T; T ~ LSON(T); TRAVNEXT; else began ANS ~ STACK(TOP); TOP -- TOP -- 7; T ~ RSON(ANS); {restructure pointers by partitioningl procedure GROW(N): integer N; ~number of elements in a subset 1 IT is root of a balanced subtree reflected by a subset, LPTR is used to temporarily store the LSON of T 1 integer T, LPTR; case N = 0 {null branchl: ANS ~ null; N = I {leaf}: TRAVNEXT; LSON(ANS), RSON(ANS) ~ null; N > I Idivisible subsetl: GROW(L(N--7)/2~); {form left subtree} LPTR TRAVNEXT; T -- ANS; -- ANS; GROW(F(N-7)/2n); RSON(T) LSON(T) ANS -- T; -- ANS; -- LPTR; if n s 2 then return; T ~ ROOT; TOP -- 0; {initialization} GROW(n); ROOT -- ANS; {new root} ~form right subtree} Martin and Ness's Algorithm?00 Communications of the ACM July 1984 Volume 27 Number 7
7 Day's Algorithm: procedure BALANCE(ROOT LSON, RSON,n): integer ROOT, n; integer array LSON, RSON; integer T, LAST_VISITED, L, R, M, BACKBONE_LENGTH; ~strlpe nodes off right-threaded tree to form backbone. T pcints to the node to be visited, LAST_VISITED holds pointer to the last visited nodel if n ~ 2 then return; T ~ ROOT; while LSON(T) ~ null do {find the first node 1 ; T ~ LSON(T); ROOT ~ T; {root of backbone} LSON(ROOT) ~ null; LAS~VISITED -- T; T -- RSON(T); while T ~ null do Itraversel if T > 0 then while LSON(T) ~ null do ; T -- LSON(T); else T ~ -(T); {backtrack} RSON(LAST_VISITED) -- T; Ichain together} LASTVISITED -- T; LSON~T) ~ null; T -- RSON(T); Irestructure backbone to a balanced tree. M is the number of transformations needed in a pass, T now polnts Eo node to be shifted out of the backbone, L is the left ancestor of T, R is the right son of T, BACKBONE_LENGTH is the number of nodes in the backbone} BACKBONE_LENGTH -- n - I; M -- LBACKBONE_LENGTH/2m; while M > 0 do {transform} T -- ROOT; ~move on ROOT in anticipation 1 ROOT -- RSON(ROOT); RSON(T) ~ LSON(ROOT); LSON(ROOT) -- T; T ~ RSON(ROOT); L ~ ROOT; for I ~ 2 to M by 1 do Ishift} R -- RSON(T); RSON(L) -- R; RSON~T) ~ LSON(R); LSON(R) ~ T; T -- RSON(R); L -- R; BACKBONE_LENGTH ~ BACKBONE_LENGTH - M - I; M -- LBACKBONE_LENGTH/2J; Day's Algorithm ]uly 1984 Volume 27 Number 7 Communications of the ACM "/01
8 TABLE I. Performance of the Algorithms Algorithm Martin/Ness Bentley Day [1] [2] [3] Chang/lyengar S P1 P2 Right-Threaded No No Yes No No No Input Tree Additional Work Space Yes Yes No Yes Yes Yes Run Time* O(n) O(n log2 n)** O(n) O(n) O(n) O(n) Parallel Execution No No No No Yes Yes Sorting No No No No No Yes (P)-Perfect or P P R P P P (R)-Route Balanced * n is the total number of nodes. ** Build and balance a tree instead of reorganizing an existing one. are able to sort the nodes and regenerate subtree pointers in the same time. Day's algorithm uses a stackless traversal to build a linked list and a loop to reorganize the linked list to a route-balanced tree structure without auxiliary storage and recursion. The average time required can be figured as shown below: T(n) ~ Con + C1 ~ (t_(n - i)/2i_j) i=1 <- Con + Cl(n - 1)(1-2-") = O(n) where Co is the average time to visit a node during traversal; C1 is the time to go through the restructuring loop once; n is the total number of nodes in a tree (n > 3); and a = L1og2n.3. Day's algorithm is a more efficient sequential balancing algorithm, if perfect balance is not required. However, in order to use this algorithm, a threaded tree has to be maintained. Properties of previously discussed algorithms are summarized in Table I for comparison. 5. SUMMARY We have presented an efficient Algorithm S to globally balance binary search trees through folding provided that the order of all nodes is predetermined and the ith item can be found given i. Balancing a tree through folding reveals parallelism in the pointer-restructuring procedure. This is a useful advantage in a parallel processing environment. Two parallel algorithms to balance binary search trees are proposed. Algorithm P1 partitions a set and balances left subtrees and right subtrees simultaneously. Another parallel algorithm, P2, actually sorts the records and makes pointer regeneration an independent activity. A comparison of our algorithms with other existing algorithms is given in Table I. Acknowledgments The authors wish to thank an anonymous referee for a number of valuable suggestions and criticisms. Thanks are due to Professor Horowitz for his comments on our paper. We would also like to thank Professor Moitra for her comments on this paper. REFERENCES 1. Bentley, J.L. Multidimensional binary search trees used for associative searching. Commun. ACM 18, 9 (Sept. 1975), Day, A.C. Balancing a binary tree. Comput. J. 19, 4 (Nov. 1978), Horowitz, E., and Sahni, S. Fundamentals of Data Structures. Computer Science Press, Inc., Potomac, MD, 1976, pp Iyengar, S.S., and Chang, H. Algorithms to create and maintain balanced and threaded binary search trees. Submitted for publication Software and Practice Journal November Iyengar, S.S., and Chang, H. A fast global algorithm to balance binary search trees. Submitted for publication, Knuth, D.E. The Art of Computer Programming, VoL 3: Sorting and Searching. Addison-Wesley Publ. Co., Inc., Reading, MA, 1973, p Martin, W.A., and Ness, D.N. Optimal binary trees grown with a sorting algorithm. Commun. ACM 15, 2 {Feb. 1972), Moitra, A., and Iyengar, S.S. Maximally parallel algorithms to balancing binary search trees. Submitted to IEEE Trans. Comput. for publication. CR Categories and Subject Descriptors: E.1 [Data]: Data Structures-- trees; F.1.2 [Computation by Abstract Devices]: Modes of Computation; F.1.3 [Computation by Abstract Devices]: Complexity Classes; F.2 [Theory of Computation]: Analysis of Algorithms and Problem Complexity General Terms: Algorithms, Theory Additional Key Words and Phrases: binary search tree, computational complexity, parallel algorithms' folding method Received 4/82; revised 3/83; accepted 11/83 Author's Present Address: Hsi Chang and S. Sitharama lyengar, Department of Computer Science, Louisiana State University, Baton Rouge, LA Permission to copy without fee all or part of this material is granted provided that the copies are not made or distributed for direct commercial advantage, the ACM copyright notice and the title of the publication and its date appear, and notice is given that copying is by permission of the Association for Computing Machinery. To copy otherwise, or to republish, requires a fee and/or specific permission.?02 Communications of the ACM July 1984 Volume 27 Number 7
S. Muthusundari. Research Scholar, Dept of CSE, Sathyabama University Chennai, India e-mail: [email protected]. 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,
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:
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
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
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
Analysis of Binary Search algorithm and Selection Sort algorithm
Analysis of Binary Search algorithm and Selection Sort algorithm In this section we shall take up two representative problems in computer science, work out the algorithms based on the best strategy to
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
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
OPTIMAL BINARY SEARCH TREES
OPTIMAL BINARY SEARCH TREES 1. PREPARATION BEFORE LAB DATA STRUCTURES An optimal binary search tree is a binary search tree for which the nodes are arranged on levels such that the tree cost is minimum.
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
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
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 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
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:
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
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:
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
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
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
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:
Chapter Objectives. Chapter 9. Sequential Search. Search Algorithms. Search Algorithms. Binary Search
Chapter Objectives Chapter 9 Search Algorithms Data Structures Using C++ 1 Learn the various search algorithms Explore how to implement the sequential and binary search algorithms Discover how the sequential
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
Lecture 10: Regression Trees
Lecture 10: Regression Trees 36-350: Data Mining October 11, 2006 Reading: Textbook, sections 5.2 and 10.5. The next three lectures are going to be about a particular kind of nonlinear predictive model,
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
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,
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
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
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
Zabin Visram Room CS115 CS126 Searching. Binary Search
Zabin Visram Room CS115 CS126 Searching Binary Search Binary Search Sequential search is not efficient for large lists as it searches half the list, on average Another search algorithm Binary search Very
Binary search algorithm
Binary search algorithm Definition Search a sorted array by repeatedly dividing the search interval in half. Begin with an interval covering the whole array. If the value of the search key is less than
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
Binary Search Trees 3/20/14
Binary Search Trees 3/0/4 Presentation for use ith the textbook Data Structures and Algorithms in Java, th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldasser, Wiley, 04 Binary Search Trees 4
Data Structures. Level 6 C30151. www.fetac.ie. Module Descriptor
The Further Education and Training Awards Council (FETAC) was set up as a statutory body on 11 June 2001 by the Minister for Education and Science. Under the Qualifications (Education & Training) Act,
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
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
DATA STRUCTURES USING C
DATA STRUCTURES USING C QUESTION BANK UNIT I 1. Define data. 2. Define Entity. 3. Define information. 4. Define Array. 5. Define data structure. 6. Give any two applications of data structures. 7. Give
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
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
Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s
Quiz 4 Solutions Q1: What value does function mystery return when called with a value of 4? int mystery ( int number ) { if ( number
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
10CS35: Data Structures Using C
CS35: Data Structures Using C QUESTION BANK REVIEW OF STRUCTURES AND POINTERS, INTRODUCTION TO SPECIAL FEATURES OF C OBJECTIVE: Learn : Usage of structures, unions - a conventional tool for handling a
Classification/Decision Trees (II)
Classification/Decision Trees (II) Department of Statistics The Pennsylvania State University Email: [email protected] Right Sized Trees Let the expected misclassification rate of a tree T be R (T ).
Output: 12 18 30 72 90 87. struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr;
50 20 70 10 30 69 90 14 35 68 85 98 16 22 60 34 (c) Execute the algorithm shown below using the tree shown above. Show the exact output produced by the algorithm. Assume that the initial call is: prob3(root)
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)
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
!"!!"#$$%&'()*+$(,%!"#$%$&'()*""%(+,'-*&./#-$&'(-&(0*".$#-$1"(2&."3$'45"
!"!!"#$$%&'()*+$(,%!"#$%$&'()*""%(+,'-*&./#-$&'(-&(0*".$#-$1"(2&."3$'45"!"#"$%&#'()*+',$$-.&#',/"-0%.12'32./4'5,5'6/%&)$).2&'7./&)8'5,5'9/2%.%3%&8':")08';:
Fast Sequential Summation Algorithms Using Augmented Data Structures
Fast Sequential Summation Algorithms Using Augmented Data Structures Vadim Stadnik [email protected] Abstract This paper provides an introduction to the design of augmented data structures that offer
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
The Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n-1)!
The Tower of Hanoi Recursion Solution recursion recursion recursion Recursive Thinking: ignore everything but the bottom disk. 1 2 Recursive Function Time Complexity Hanoi (n, src, dest, temp): If (n >
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
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
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
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
Resource Allocation Schemes for Gang Scheduling
Resource Allocation Schemes for Gang Scheduling B. B. Zhou School of Computing and Mathematics Deakin University Geelong, VIC 327, Australia D. Walsh R. P. Brent Department of Computer Science Australian
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
Tree Visualization with Tree-Maps: 2-d Space-Filling Approach
I THE INTERACTION TECHNIQUE NOTEBOOK I Tree Visualization with Tree-Maps: 2-d Space-Filling Approach Ben Shneiderman University of Maryland Introduction. The traditional approach to representing tree structures
- 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
TOWARDS SIMPLE, EASY TO UNDERSTAND, AN INTERACTIVE DECISION TREE ALGORITHM
TOWARDS SIMPLE, EASY TO UNDERSTAND, AN INTERACTIVE DECISION TREE ALGORITHM Thanh-Nghi Do College of Information Technology, Cantho University 1 Ly Tu Trong Street, Ninh Kieu District Cantho City, Vietnam
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:
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
Persistent Data Structures and Planar Point Location
Persistent Data Structures and Planar Point Location Inge Li Gørtz Persistent Data Structures Ephemeral Partial persistence Full persistence Confluent persistence V1 V1 V1 V1 V2 q ue V2 V2 V5 V2 V4 V4
On the k-path cover problem for cacti
On the k-path cover problem for cacti Zemin Jin and Xueliang Li Center for Combinatorics and LPMC Nankai University Tianjin 300071, P.R. China [email protected], [email protected] Abstract In this paper we
Echidna: Efficient Clustering of Hierarchical Data for Network Traffic Analysis
Echidna: Efficient Clustering of Hierarchical Data for Network Traffic Analysis Abdun Mahmood, Christopher Leckie, Parampalli Udaya Department of Computer Science and Software Engineering University of
Loop Invariants and Binary Search
Loop Invariants and Binary Search Chapter 4.3.3 and 9.3.1-1 - Outline Ø Iterative Algorithms, Assertions and Proofs of Correctness Ø Binary Search: A Case Study - 2 - Outline Ø Iterative Algorithms, Assertions
Picture Maze Generation by Successive Insertion of Path Segment
1 2 3 Picture Maze Generation by Successive Insertion of Path Segment 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32. ABSTRACT Tomio Kurokawa 1* 1 Aichi Institute of Technology,
Data Structures and Algorithms(5)
Ming Zhang Data Structures and Algorithms Data Structures and Algorithms(5) Instructor: Ming Zhang Textbook Authors: Ming Zhang, Tengjiao Wang and Haiyan Zhao Higher Education Press, 2008.6 (the "Eleventh
CMSC 858T: Randomized Algorithms Spring 2003 Handout 8: The Local Lemma
CMSC 858T: Randomized Algorithms Spring 2003 Handout 8: The Local Lemma Please Note: The references at the end are given for extra reading if you are interested in exploring these ideas further. You are
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,
Vector storage and access; algorithms in GIS. This is lecture 6
Vector storage and access; algorithms in GIS This is lecture 6 Vector data storage and access Vectors are built from points, line and areas. (x,y) Surface: (x,y,z) Vector data access Access to vector
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
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
Parallelization: Binary Tree Traversal
By Aaron Weeden and Patrick Royal Shodor Education Foundation, Inc. August 2012 Introduction: According to Moore s law, the number of transistors on a computer chip doubles roughly every two years. First
Outline. Introduction Linear Search. Transpose sequential search Interpolation search Binary search Fibonacci search Other search techniques
Searching (Unit 6) Outline Introduction Linear Search Ordered linear search Unordered linear search Transpose sequential search Interpolation search Binary search Fibonacci search Other search techniques
Data Structures, Practice Homework 3, with Solutions (not to be handed in)
Data Structures, Practice Homework 3, with Solutions (not to be handed in) 1. Carrano, 4th edition, Chapter 9, Exercise 1: What is the order of each of the following tasks in the worst case? (a) Computing
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)
A Deduplication-based Data Archiving System
2012 International Conference on Image, Vision and Computing (ICIVC 2012) IPCSIT vol. 50 (2012) (2012) IACSIT Press, Singapore DOI: 10.7763/IPCSIT.2012.V50.20 A Deduplication-based Data Archiving System
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
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
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
Lecture 18: Applications of Dynamic Programming Steven Skiena. Department of Computer Science State University of New York Stony Brook, NY 11794 4400
Lecture 18: Applications of Dynamic Programming Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.sunysb.edu/ skiena Problem of the Day
Data Structures and Data Manipulation
Data Structures and Data Manipulation What the Specification Says: Explain how static data structures may be used to implement dynamic data structures; Describe algorithms for the insertion, retrieval
Merkle Hash Trees for Distributed Audit Logs
Merkle Hash Trees for Distributed Audit Logs Subject proposed by Karthikeyan Bhargavan [email protected] April 7, 2015 Modern distributed systems spread their databases across a large number
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
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
Sorting Algorithms. Nelson Padua-Perez Bill Pugh. Department of Computer Science University of Maryland, College Park
Sorting Algorithms Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park Overview Comparison sort Bubble sort Selection sort Tree sort Heap sort Quick sort Merge
CS473 - Algorithms I
CS473 - Algorithms I Lecture 4 The Divide-and-Conquer Design Paradigm View in slide-show mode 1 Reminder: Merge Sort Input array A sort this half sort this half Divide Conquer merge two sorted halves Combine
Algorithms. Margaret M. Fleck. 18 October 2010
Algorithms Margaret M. Fleck 18 October 2010 These notes cover how to analyze the running time of algorithms (sections 3.1, 3.3, 4.4, and 7.1 of Rosen). 1 Introduction The main reason for studying big-o
Introduction to Algorithms March 10, 2004 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser Quiz 1.
Introduction to Algorithms March 10, 2004 Massachusetts Institute of Technology 6.046J/18.410J Professors Erik Demaine and Shafi Goldwasser Quiz 1 Quiz 1 Do not open this quiz booklet until you are directed
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
CS473 - Algorithms I
CS473 - Algorithms I Lecture 9 Sorting in Linear Time View in slide-show mode 1 How Fast Can We Sort? The algorithms we have seen so far: Based on comparison of elements We only care about the relative
Image Compression through DCT and Huffman Coding Technique
International Journal of Current Engineering and Technology E-ISSN 2277 4106, P-ISSN 2347 5161 2015 INPRESSCO, All Rights Reserved Available at http://inpressco.com/category/ijcet Research Article Rahul
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
6. Standard Algorithms
6. Standard Algorithms The algorithms we will examine perform Searching and Sorting. 6.1 Searching Algorithms Two algorithms will be studied. These are: 6.1.1. inear Search The inear Search The Binary
Caching XML Data on Mobile Web Clients
Caching XML Data on Mobile Web Clients Stefan Böttcher, Adelhard Türling University of Paderborn, Faculty 5 (Computer Science, Electrical Engineering & Mathematics) Fürstenallee 11, D-33102 Paderborn,
A Branch and Bound Algorithm for Solving the Binary Bi-level Linear Programming Problem
A Branch and Bound Algorithm for Solving the Binary Bi-level Linear Programming Problem John Karlof and Peter Hocking Mathematics and Statistics Department University of North Carolina Wilmington Wilmington,
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
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
