IEEE TRANSACTIONS ON COMPUTERS, VOL. C-27, NO. 5, MAY 1978 Rebalancing Height Balanced Trees FABRIZIO LUCCIO AND LINDA PAGLI Abstract-A new balancing technique for binary search trees is presented, based on the repositioning of k + 1 nodes (k-rotation) Some properties of k-rotation are shown, and bounds to k are derived. The performance of such a technique is discussed on the basis of the length of node search and the frequency of tree rebalancing. Index Terms-Height balanced trees, information storage and retrieval, rebalancing, rotation, search length. I. INTRODUCTION B INARY search trees are important structures for ordered data organization, since they can be searched through and updated in average logarithmic time. In addi- tion, if binary search trees are kept balanced in height, searching and updating are logarithmic operations even in the worst cases [1], [4], [5]. According to the general definition introduced in [3], height-balanced binary trees (Ahb-trees) have the property that, for every node, the heights of the right and left subtrees differ at most an integer A. lhb-trees are the well-known AVL trees. For a general value of A, tree restructuring after insertion or deletion of nodes may be accomplished by the classical operations (rotations) used for lhb-trees [3]. The average tree height-hence, the average search length- increases with A, while the average amount of restructuring decreases with increasing A. It is worthwhile to note, however, that restructuring may be required after the insertion (or deletion) of almost every new node. The worst case is the one of a tree growing by subsequent insertions of nodes presented in increasing order. Such a construction for a 3hb-tree composed of the alphabetically ordered nodes A to J is shown in Fig. 1: steps marked by a star required rebalancing. It can be easily proven that rebalancing is due at every step, except for the initial steps 1 to A, and for steps s = 2- 1 + A (k = 1, 2, -) where the new node is inserted into a perfectly balanced tree of 2k - 1 nodes with an additional rightmost chain of A - 1 nodes (in the example, s = 4, 6, and 10). Since during the insertion of n nodes (i.e., during the first n steps) the number of encountered steps of type s is [log2 (n + 1 - A)l rebal- ancing is due at n - [1lg2 (n + 1 - A)] - A steps, that is at 0(n) steps. Manuscript received August 17, 1976; revised May 5, 1977. This work was supported in part by the National Research Council of Italy (CNR) under Grant 75.01035.01. This work was partially done while F. Luccio was visiting the Department of Computer Science, University of Illinois at Urbana, IL. The authors are with the Istituto di Scienze dell'Informazione, Univer- sity of Pisa, Pisa, Italy. Obviously, the result in Fig. 1 is due to the balancing technique used. In [3], the idea of "balancing as closely as possible" versus classical balancing was briefly examined and discarded because of possible undesired effects. In this work we will resume this point, and thoroughly discuss alternative balancing techniques. Let hi denote the height of a tree i. For a node N with left and right subtrees iji and 0/, respectively, we classically define the balance bN as bN = h/, - hqi/. In a balanced tree, bN < A for each node N. We note that in Fig. 1 there is always at least one node N with bN = A = 3, except for the first A steps, and for steps 5 and 9 where the maximum balance is 2. For example, at step 7 it is bB = 3, and the successive insertion of node H unbalances node B, thus requiring rebalancing at step 8. Still, it results bE = 3, and rebalancing is newly needed at step 9. However, if a different rebalancing technique were adopted at step 8, by pulling node E at the root, the new configuration shown in Fig. 2 would be obtained, where the maximum balance is 2, hence no unbalancing may occur at the succeeding step. II. CRITICAL PATHS AND CRITICAL NODES To study the balancing technique we discuss some proper- ties of Ahb-trees. Let - be one such tree, ROOT(T) and LEAF(T), respectively denote the root and a leaf of -. For node K e T, let SON(K), LEFTSON(K), RIGHTSON(K), DESCENDANT(K), LEFTDESCENDANT(K), RIGHTDESCENDANT(K), and FATH- ER(K), respectively, denote a son, the left son, the right son, a descendant, a left descendant, a right descendant, and the father of K in Z. A path p E T is an ordered set of nodes {K1, K2, ..., Kr} such that Ki1, = soN(K1), 1 < i < r - 1. We denote p = K1, Kr; K1 = HEAD(P). r is the length of p. A single node is a path of length one. A node K E p is discordant with p if bK < 0, RIGHTSON(K) E p, or bK > 0, LEFTSON(K) E p; otherwise, K is concordant with p. (In particular, if bK = 0, K is concordant with p.) A path ROOT(T), LEAF(T) iS total. For a leafL, the total path containing L will be denoted by v(L). Definition 1: A path ir is critical if all its nodes are 0018-9340/78/0500-0386$00.75 C) 1978 IEEE 386