On Dynamic Optimality for Binary Search Trees

Does there exist O(1)-competitive (self-adjusting) binary search tree (BST) algorithms? This is a well-studied problem. A simple offline BST algorithm GreedyFuture was proposed independently by Lucas and Munro, and they conjectured it to be O(1)-comp…

Authors: ** Navin Goyal (Microsoft Research, India) Manoj Gupta (IIT Delhi) **

On Dynamic Optimalit y for Binary Searc h T rees Na vin Go y al ∗ naving o@micr osoft.com Mano j Gupta † gmanoj @cse.i itd.ernet.in Abstract Do e s there exist O (1)- c ompe titive (self-adjusting) binary sea rch tree (BST) algor ithms? This is a well-studied problem. A simple offline BST algorithm GreedyF uture was prop osed indepen- dent ly b y Lucas [5] and Munro [6], and they conjectured it to b e O (1 )- comp e titive. Recently , Demaine et al. [2] gav e a geometric view of the BST problem. This view allow ed them to give an online algor ithm GreedyArb with the same cos t a s GreedyF uture. How ever, no o ( n )- comp etitiv e r atio w as known for GreedyArb. In this pap er we mak e prog r ess to w ards proving O (1)- c ompe titive ratio for Greedy Ar b by showing that it is O (log n )-comp etitiv e. 1 In tro duction Binary searc h trees ( BST) are a data s tructure for the d ictionary problem. There are many examp les of (static or offline) binary searc h trees, e.g. A VL trees and r ed-blac k trees, w h ic h take O (log n ) w orst-case time p er searc h query (and p ossibly for other t yp es of op erations suc h as ins er t/delete; but w e w ill confine ourselves to searc h queries in this n ote) on n ke ys. F or static tr ees, O (log n ) b ound cannot b e improv ed. B ut tr ees that can change shap e in resp ons e to qu eries can p oten tially ha v e smaller amortized search time p er qu ery . In this case, comp etitiv e analysis is u sed to measure the p erformance. Spla y trees [9] of Sleator and T arjan are simple self-adjusting binary search trees which are O (log n )-comp etitiv e. Sleator and T arjan [9] conjectured that Spla y trees w ere in fact O (1)- comp etitiv e. Unfortunately , d espite considerable efforts o (log n )-comp etitiv eness f or S p la y trees is not kno wn; see, e.g., [8 ] for a r ecen t d iscussion. But ev en a p oten tially easier qu estion remains op en: Is there any BST algorithm whic h is O (1)-comp etitiv e? In the past decade pr ogress wa s made on this question and BST algorithms with b etter comp etitiv e r atio w ere disco v ered: T ango trees [3] were the first O (log log n )-comp etitiv e BSTs; Multi-Spla y trees [10 ] and Zipp er trees [1] also h a ve the same comp etitiv e ratio along w ith some additional prop erties. Analyses of these trees use low er b ound for the time tak en to complete a sequence of requests. Wilb er [11] ga ve t wo d ifferent su c h low er b ounds. Wilber’s fir st lo w er b ou n d is u sed in [3], [10] and [1] to obtain O (log log n ) comp etitiv eness. These tec hn iques based on Wilb er’s b ound hav e so far failed to giv e o (log log n )-comp etitiv eness. Ev en the off-line pr oblem is n ot w ell-un d ersto o d, and the b est p erformance guarantee known is the same as the online guaran tee obtained by T ango trees just men tioned. Lucas [5] and Munr o [6], indep end en tly prop osed an offline BST algorithm GreedyF utu r e (this name comes fr om [2]) and ∗ Microsof t Researc h, Ind ia † I IT Delhi: W ork done while visiting Microsoft R esearc h , Ind ia 1 they conjectured that GreedyF uture wa s O (1)-comp etitiv e. But ev en o ( n )-comp etitiv eness was not kno wn for GreedyF uture. Our m ain result, Th eorem 1.1 b elo w, imp lies that GreedyF uture is O (log n )-comp etitiv e, thus making progress to w ards O (1)-competitiv e ratio for GreedyF u tu re. A new lin e o f atta c k on the B ST problem w as giv en b y Demaine et al. [2]. They g a ve a ge ometric view of th e problem of d esignin g BST algorithms. This allo w ed them to translate conjectures and results ab out BSTs in to intuitiv ely app ealing geometric statemen ts. W e no w qu ic kly describ e their geometric view. 1.1 Problem Definition In the BST p roblem we wan t to main tain n keys in a bin ary s earch tree to serv e searc h requests. In resp onse to eac h searc h r equest, the algorithm is allo w ed to mod ify the stru cture of the tree, b ut this change in the stru cture adds to the searc h cost. W e are inte rested in d esigning BST algorithms with small amortized searc h cost, in other words, algorithms with small comp etitiv e ratio. Since w e will only wo rk in the geometric view, w e define the BST pr oblem formally only in the geometric mo del and omit th e formal definition of the BST mo del; please see [2] for d etails. In the geometric view of the BS T p roblem, we w ill work in the tw o-dimensional p lane with a fixed cartesian coord inate system. W e ha v e n k eys in the tree, wh ic h we will assume to b e 1 , 2 , . . . , n . And w e ha ve n s earch queries coming at time instants 1 , 2 , . . . , n , one for eac h key (this, of course, is not the general situation as a k ey could b e searc hed more than once, b ut as discuss ed in [2], we can work with th is case without loss of generalit y ). W e can represent these n q u eries as p oin ts in the plane: Let X = { p 1 , p 2 , . . . , p n } b e a set of n p oin ts in the t w o-dimensional plane d efine as follo ws. Let the x -axis represen t the key space and y -axis r ep resen t time. Eac h p i is represented by a p air ( i, t i ) w here b oth i and t i are intege rs. W e sa y that the key i arriv e at time t i . F o r a p oin t p , let p.x denote its x -co ordinate and p.y denote its y -coord inate. Clearly for all distinct p, q ∈ X w e ha v e p.x 6 = q .x , p.y 6 = q .y . That is to sa y , there exists exactly one p oint fr om X on line x = i , for 1 ≤ i ≤ n . S im ilarly , th er e exists exactly one p oint from X on line y = i , for 1 ≤ i ≤ n . F or a pair of p oin ts p, q not on the same horizon tal or vertic al line, the axis-aligned rectangle formed by p and q is denoted by  pq Definition 1.1 ([2]) . A p air of p oints ( p, q ) is said to b e arb orally satisfied with r esp e ct to a p oint set P , if (1) p and q lie on the same horizonta l and vertic al line, or (2) ∃ r ∈ P \ { p, q } such that r lies i nside or on the b oundary of  pq . A p oint set P is arb orally satisfied if al l p airs of p oints in P ar e arb or al ly satisfie d with r e sp e ct to P . Arb orally Satisfied Set (ArbSS) Problem : Given a p oint set X , find a minimum c ar di- nality p oint set Y such that X ∪ Y is arb or al ly satisfie d. [While sev eral d efinitions here are from [2], w e ha v e c h osen to use less colorful abbr eviations than in [2].] Let MinAr b( X ) d enote the minimum cardinalit y p oin t set whic h solve s the ArbSS p roblem on a p oin t s et X . [2] shows th at the BST view and the geometric view are essent ially equiv alen t. In particular, if OPT( S ) is the minimum cost of compu ting a request sequence S , then MinArb( X ) = Θ(OPT( S )), where X is the set of p oint s in the plane corresp onding to S . 1.2 GreedyArb Algor it hm There is a n atural greedy algorithm f or the ArbSS pr oblem: 2 key time key time Figure 1: Th e red p oint are the p oin t set X and the blue p oin ts are add ed by GreedyArb Algorithm Sw eep the p oint set X with a h orizon tal line by incr easing the y -coord inates. Let the p oint p b e pr o cessed at time p.y . A t time p.y , p lace the minimal num b er of p oin ts on line y = p.y to satisfy th e rectangles w ith p as one end p oint and other endp oin t in X ∪ Y with y -co ordinate less th an p.y . Th is minimal set of p oin t M p is uniqu ely defined: for an y unsatisfied rectangle formed with ( s, p .y ) as one of the corner p oin t, add a p oin t at ( s, p.y ). GreedyArb is an online algorithm in the sense that at eac h time instant it adds a set of p oin ts so that the resulting set is arb orally satisfied, and it do es so w ith ou t the kn o w ledge of the f u - ture requests. [2] sh o w s that GreedyAr b can b e used to der ive an online BST algorithm with the same comp etitiv e ratio. It is conjectured that Gr eedyArb is O (1)-competitiv e, that is, the n um b er of p oints added b y the GreedyAr b algorithm on a p oin t set X is O ( | M i nAr b ( X ) | ). S ur- prisingly , GreedyArb has th e same comp etitiv e r atio as the aforemen tioned (offline) BST algorithm GreedyF utu r e [2]. T o our k n o w ledge, no non-trivial (i.e. o ( n )) comp etitiv e f actor was known for GreedyF utu r e or GreedyArb. In this p ap er w e pro v e the f ollo wing result: Theorem 1.1. Gr e e dyArb is O (log n ) -c omp etitive. Our analysis of GreedyArb exp oses some in teresting combinatorial p rop erties of GreedyArb algorithm, whic h may b e us eful in fu rther impr oving the comp etitiv e ratio. [After we had written our results, it came to our atten tion that Patrasc u in his talk slides [7] has claimed that with Iacono h e has pro v ed th at Gr eedyArb is O (log n )-comp etitiv e. T o our knowle dge, this result has not app eared anywhere, and our work w as done indep enden tly .] 2 Pro of of the main result In this section we pro v e Theorem 1.1. Let us fi rst outline our approac h. Let X b e the inp ut set of n p oin ts that w e w an t to arb orally satisfy by addin g more p oints. W e wan t to prov e that GreedyArb adds O ( n log n ) p oin ts. W e pr ov e this by using the stand ard recurrence T ( n ) = 2 T ( n/ 2) + O ( n ), where T ( n ) is the m axim u m p ossible n um b er of p oin ts added by GreedyArb on sets of n p oin ts. W e in terpret the previous equation as f ollo ws: Divide the n p oint s in to tw o equal sets P (points with x -co ordinate in { 1 , 2 , . . . , n / 2 } ) and Q (rest of th e p oints). F or sets P and Q w e defi ne regions of the plane R P and R Q in the n atural w ay: R p = { r | 1 / 2 < r.x < n/ 2 + 1 / 2 } , and similarly R Q = { r | n/ 2 + 1 / 2 < r .x < n + 1 / 2 } . W e sh o w that the total num b er of p oints added by GreedyArb in R p when pro cessing p oin ts in Q is O ( n ), and by sym m etry , the 3 p 1 p 2 p 3 R P R Q t Figure 2: p 1 , p 2 and p 3 are corner p oin ts in P for Q at time t n um b er of p oin ts added in R q when p ro cessing p oints in P is O ( n ). T h is giv es the recurren ce ab o ve for the top lev el. But w e ha v e to prov e th at th e prop erty holds more generally for our recursion to hold at all lev els. In general, we show the follo wing: Giv en an y set of 2 k consecutiv e ke ys, with P consisting of the p oint s corresp ond ing to the first k keys and Q consisting of the p oints corresp onding to the last k keys. Then the total n umber of p oints added in R Q b y Gr eedyArb when pro cessing p oints in P is O ( k ), and similarly , the n umber of p oin ts add ed in R P when pro cessing p oint s in Q is O ( k ). Th e rest of the pro of is devote d to showing this last statemen t. O nce we pr ov e this, we get the ab o v e r ecur rence and that immediately completes the p ro of of Theorem 1.1. W e no w pro ceed with the formal pro of. Let S = { p j , p j + 1 , . . . , p j + 2 k − 1 } b e a set of 2 k consecutiv e p oint s in X su ch that p i +1 .x = p i .x + 1 ∀ j ≤ i < j + 2 k − 1. L et P = { p j , p j + 1 , . . . , p j + k − 1 } and Q = { p j + k , p j + k + 1 , . . . , p j + 2 k − 1 } . Define R P to b e the region b et ween the ve rtical lines passing th rough p oints j − 1 / 2 and ( j + k − 1) + 1 / 2; similarly , R Q is the r egion b et wee n the v ertical lines p assing thr ough the p oint s ( j + k − 1) − 1 / 2 and ( j + 2 k − 1) + 1 / 2. Let P l = { p 1 , p 2 , . . . , p j − 1 } and Q r = { p j + 2 k , p j + 2 k +1 , . . . , p n } . Let R P l b e the region to the left of R P suc h that it con tains all the p oint P l . Similarly , R Q r is the region to the r igh t of R Q and it con tains all the p oin ts in Q r . Let X r ′ .x . That is, r is the r ightmost p oint in the set M P p ∪ { p } . No p oin t in ( M P p ∪ { p } ) \ { r } can b e a corner p oin t f or Q at time t b ecause eac h one of them has p oin t r to th eir righ t in R P . Only p oin t r can p otent ially b e a corner p oint among the p oint s in M P p ∪ { p } . So the num b er of corner p oin ts can increase b y at most one at time t + 1. Lemma 2.2. L et p ∈ X b e the p oint arriving at time t . If p ∈ Q ∪ Q r , then (1) if | M P p | = 0 , then | C t +1 | = | C t | ; and (2) if | M P p | > 0 , then | C t +1 | ≤ | C t | − ( | M P p | − 1) . 4 Pr o of. If | M P p | = 0, then the n um b er of corner p oin ts cannot increase as there are n o p oints on line y = t in region R P . S o let | M P p | > 0. The execution of GreedyArb tries to satisfy all th e unsatisfied rectangles with one corner p . F o r eac h mark ed p oint in M P p , the corresp onding other corner of the rectangle must lie in C t . Let N P p = { q | q ∈ C t and GreedyArb add s a p oin t r ∈ M P p due to u nsatisfied rectangle  q p } . A t time t + 1, all the p oint s in N P p cease to remain the corner p oint , b ecause ∀ q ∈ N P p ∃ r ∈ M P p suc h that r .x = q .x and r.y > q .y . S o the decrease in the num b er of corner p oin ts is at least | N P p | = | M P p | . As in the p r o of of Lemma 2.1, only one p oin t in M P p can b ecome a corner p oin t for Q at time t + 1. So C t +1 ≤ C t − ( | M P p | − 1). Assume that P l = ∅ . Let p b e th e last p oint to arr iv e in s et Q . App lying L emm as 2.1 and 2.2 inductiv ely we get, | C p.y | ≤ | C 1 | + X q ∈ P 1 − X q ∈ Q ∪ Q r M P q 6 = φ ( | M P q | − 1). S ince | C 1 | = 0 this give s, X q ∈ Q ∪ Q r M P q 6 = ∅ ( | M P q | − 1) ≤ −| C p.y | + | P | , this giv es X q ∈ Q M P q 6 = ∅ ( | M P q | − 1) ≤ −| C p.y | + | P | , and so X q ∈ Q M P q 6 = ∅ | M P q | ≤ | P | + X q ∈ Q M P q 6 = φ 1 ≤ | P | + | Q | ≤ 2 k . So if P l = ∅ , then the num b er of p oint s added wh ile pro cessing p oints in Q in region R P is O ( k ). But if P l 6 = ∅ , then th e quanti t y P q ∈ Q | M P q | ma y b e larger. W e will argue that it’s still O ( k ). W e denote the set of all the p oin ts added by Gr eedy Ar b as Y . Definition 2.2. F or a p oint p ∈ P let T p p.y . L et q b e the p oint in T p

Original Paper

Loading high-quality paper...

Comments & Academic Discussion

Loading comments...

Leave a Comment