• Nenhum resultado encontrado

Weconsidertheproblem of storingitemsfromatotally orderedsetinasearchtreeso that the access timefor agivenitemdependson aknown estimate ofthe access frequency of the item

N/A
N/A
Protected

Academic year: 2022

Share "Weconsidertheproblem of storingitemsfromatotally orderedsetinasearchtreeso that the access timefor agivenitemdependson aknown estimate ofthe access frequency of the item"

Copied!
24
0
0

Texto

(1)

BIASED SEARCH

TREES*

SAMUEL W. BENTf, DANIEL D. SLEATOR: AND ROBERT E. TARJANt

Abstract. Weconsidertheproblem of storingitemsfromatotally orderedsetinasearchtreeso that the access timefor agivenitemdependson aknown estimate ofthe access frequency of the item. We describe two relatedclasses ofbiasedsearchtreeswhoseaverageaccess time is within a constant factor of theminimum andthat are easytoupdateunderinsertions,deletions and more radicalupdate operations.

Wepresent andanalyzeefficientupdate algorithmsfor biasedsearchtrees.Welistseveralapplications of suchtrees.

Keywords,optimumsearchtrees, binary search trees,datastructures, algorithms, complexity

1. Introduction. The followingproblem,which weshall callthe dictionary problem, occursfrequentlyin computerscience. Weare givenatotally ordereduniverse U. We wish to represent sets $

_

U in such a way that the following access and update

operations are efficient"

access(i,

S)"

Ifitem is anelement of set

S,

return apointerto its location.

Otherwise return a special null pointer.

insert(i,

S):

Insertitem into set $.Weallow an insertion to take place only if is not initially an elementof$.

delete(i,

S)"

Delete item fromsetS. Weallowa deletiononlyif isinitially in S.

In addition to access, insert and delete, the following more radical update operations are often useful"

join

(R,

$)" (two-wayjoin). Returntheset consisting of theunion ofR and

$.Thisoperationdestroys R and

S,

and is allowedonlyifevery item in R is less than every item in S.

(Thus

a join can be regarded astheconcatenation of thesorted sets R and $.) join

(R,

i,

S):

(three-wayjoin). Returnthesetconsisting of theunionof

R,

{i}

and S. This operationdestroys R and

S,

and isallowed only if every itemin R islessthan and everyitem in Sisgreaterthan

i.

split(i,$)" Split S into three sets:

P,

containing all items in S lessthan i;

Q,

containing if S (three-way split) and nothing if i$

(two-way

split);and

R,

containingallelementsin$greaterthan i. This operation destroys S.

One kind of data structurethat efficiently supports these operations is a search tree.

A

search tree is an ordered tree (Appendix

A

contains our tree terminology) containing the items ofa set in its leaves, in left-to-rightorder, one item per leaf. In ordertofacilitatethe access operation,we mustalsostoreauxiliary items, called keys, intheinternalnodes.(Appendix Bdiscussesthe placement,use andupdating ofkeys.)

To

access an item, we start atthe root ofthe tree, compare the item being accessed with the key(s) in this node, go to a child determined by the outcome of the com- parison(s), and continue in thisway untilreaching a leaf. Thisleafcontains theitem if it isin the tree. With this access method,thetime to access an item isproportional

*Received by the editors March 15, 1983, and in revised form March7, 1984. Research partially supportedbythe National Science FoundationundergrantMCS82-03238.

*

ComputerScienceDepartment,UniversityofWisconsin, Madison,Wisconsin53706.

,

AT&TBellLaboratories, MurrayHill, New Jersey07974.

545

Downloaded 10/24/14 to 143.107.45.106. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

(2)

546 S.W. BENT, D. D. SLEATOR AND R. E. TARJAN

tothedepth of the leaf containing it, if we assume a fixedupper bound on thedegree ofanode.

If the search tree satisfies an appropriate balance condition, then the height of thetree, and hence theworst-caseaccesstime,is O(log

n) ,

where n isthe numberof

items intheset. Foracomparison-based modelofcomputation,onecanprovealower boundoff(log

n)

onthe worst-case access time;thus balancedtrees haveaworst-case access time within aconstantfactor ofthe minimum. Kinds of balancedtrees include height-balanced trees [2], [20], two-three trees [3], B-trees [6], weight-balanced trees [27],red-blacktrees 12]and many others. Thesekindsof trees all have the additional property that each of the update operations can becarried out in O(log

n)

time.

In many applications of search trees, the access frequencies are different for different items. In such a situation we would like to bias the searchtree, so that the more-frequently needed items can be accessed fasterthan the less-frequently needed ones. In order to treat this problem formally let us assume that each item has a knownweightw,>0representing theaccessfrequency.Ameasure ofthe averageaccess time is

(d,+ l)

Wi

iS W

where W

,s

w,isthe sumof the weights of the items in the set andd, isthedepth inthe searchtreeof the node containingitem i.Our goalis tomakethe totalweighted depth

Y.,s

w,di as small as possible while preservingtheabilityto updatethe search treerapidly.We callthisthe biaseddictionaryproblem. Itis natural in thisproblemto allow an additional operation forchanging the weight ofanitem"

reweight(i,w, S): Redefine theweight ofitem in set Sto be w.

In this paper we shall propose two kinds oftrees, which we call biased search trees, for solving the biaseddictionary problem. Ourresults provide not only specific kindsof search trees, but also ageneralmethodology for converting almostanyclass of balanced search trees into asimilar but moregeneral class ofbiased search trees.

Inaddition todevelopingnewideas, the paper extendsand refines ideas firstpresented earlier in preliminary form[7], [8].

Thepapercontains five sections. Section 2 reviewsrelevantpreviouswork. Sections 3 and 4define andanalyze the propertiesof two kindsofbiased search trees. Section 3 describes biased 2,b trees, which are analogous to 2,3 trees and B-trees. Section 4 describes biasedbinary trees,whichgeneralize aparticularkind ofred-blacktree 12]

sometimes called asymmetric binaryB-tree [5]. Section 5 summarizes our results and discusses several applications and related work. Appendix A contains our tree ter- minology. Appendix B describes the arrangement of the keys in a search tree, their use for searchand their updating.

2. Previousresearch. Severalknownresults bearonthebiaseddictionary problem.

The first and mostimportant is astandard theorem of informationtheory.

THEOREMA 1]. Consider any search tree T

for

a set S.

If

every node

of

Thas at

mostbchildren, then thetotal weighteddepth

,s

w,d, isatleast

W,,

sp,logb(l/p,), where p,--w,/ W.

InlightofTheorem

A,

ourgoalis to deviseclasses ofsearchtreeswiththe property thatd, O(log(

W

w,))foreach item i, sinceanysuch search tree has minimumaverage

Iffand g are functions of anonnegative real number x,we write"f(x) is O(g(x))" ifthere are positiveconstantscland c2 suchthatf(x)-<cg(x)+c2 for allx.Wewrite"f(x)isf(g(x))"ifg(x)isO(f(x)).

Downloaded 10/24/14 to 143.107.45.106. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

(3)

access timeto within a constant factor. We shall call O(log(W/wi)) the ideal access time of item i. If all item weights are equal the ideal access time for every item is O(log

n)

and any balanced searchtree has ideal access time forall items.

Much previous work deals with the caseof a static search tree. Supposewe are givenafixed setSwhoseitemshaveknownweightsand we want to construct asearch tree ofexactly minimum total weighted depth. We call such a search tree optimum.

Knuth [19]

(see

also Yao

[33])

has given a dynamic programming algorithm that computes anoptimum searchtreeamong binarytreescontainingoneitemperinternal node(insteadofoneitemper

leaf).

Knuth’s algorithmrunsin

O(n 2)

time and allows forthe possibility that weightsare given notonly for the items in the setbutalso for thegaps between items; these gapscorrespondto the possible ways to search for an item not in the set.

Analgorithm ofHuandTucker 17]

(see

alsoGarsia and Wachs 11],

Hu,

Kleitman and Tamaki 16], andHu

15])

finds an optimumsearchtreeamongbinary trees with oneitem perleaf, assuming no weights are given for the gaps. (This is aspecial case of the problem solved by

Knuth.)

The Hu-Tucker algorithmruns in

O(n

log

n)

time andresembles Huffman’s algorithm 18]forcomputinganoptimum binary prefixcode.

Fredman [10], Mehlhorn [24] and Korsch [21] have proposed O(n)-time algorithms that construct binary search trees whose total weighted depth is within a constant factor of minimum.

None of these algorithms is satisfactoryin the dynamic case, since they require

Completely

restructuring the tree (spending

l(n)

time) each time an update occurs.

Several authors haveproposedclasses of biasedsearchtreesthatare easier toupdate.

Baer[4] gave a heuristicfor rebalancing biased weight-balanced search trees,but he gave no theoretical results, and indeed his trees do not have ideal access time inthe worst case. Unterauer [32]described a class of biasedweight-balanced trees that have ideal access time, but he did not analyze the worst-case time required for updates.

Mehlhorn

[26]

described aclassofbiasedsearchtreesbasedonweight-balanced trees, called D-trees. D-trees have ideal worst-case access time and require O(min {n,log

(W’/wo)})

timefor insertion,where Wo is theweight of the smallest item and

W’

isthe total weight of allthe items intheset afterthe insertion. Mehlhorn[25]

subsequently showed that a weight change in a D-tree can be performed in O(log

(max { W,

W’}/min {wi, w’i}))time,wherew,

w, W, W’

aretheoldweight of the reweighted item, the new weight ofthis item, the old totalweight and the new total weight, respectively. Kriegel and Vaishnavi [22] proposed another version ofbiased search trees with timeboundssimilar to those of Mehlhorn.

The kindsofbiasedsearchtrees wepropose herearesimplerthanthoseproposed by Mehlhorn and Kriegel and Vaishnavi. They also have faster running times for insertion,deletion, join and split. (Mehlhorndoes notconsiderjoinandsplit; Kriegel and Vaishnavi’sboundforsplitisthesame asoursbuttheirbound for joinis

worse.)

3. Biased2,btrees. Ourfirstclassofbiasedsearchtreesgeneralizes 2,3 trees [3].

A2,b tree is a searchtree each ofwhose internalnodes has at least 2 and at most b children, where b is anyfixed integer greater than two. We define the rank

s(x)

ofa node x in a2,b tree recursivelyby

s(x):{

Jig

w]

if x is a leafcontainingitem i,2

+

max

{s(y)ly

is achild of

x}

ifx is an internal node.

Wedenote log2xby lgx.

Downloaded 10/24/14 to 143.107.45.106. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

(4)

548 S. W. BENT, D. D. SLEATOR AND R. E. TARJAN

Thisdefinition implies that ify isanode otherthanthe tree root and x isits parent, then s(y)

<= s(x)

1. We call y major if s(y)

s(x)-1

and minor if

s(y) < s(x)-1.

Byconventionthe root ismajor. A locally biased 2,b tree is a 2, b tree satisfying the following property, which constrains the environmentofminor

nodes-(see

Fig.

1).

FIG. 1. Alocallybiased2,3 tree.Leavesarerectangles, internalnodesarecircles. Numbers insideleaves areweights. Numberstotheleft ofnodes areranks" those above nodes(in parentheses) arecreditcounts.For claritytheitems innodes are omitted.

Localbias.

Any

neighboring sibling ofaminornodeis a majorleaf.

(We

saythe tree is locally biased atthe minor

node.)

A 2,b tree is balanced if every leaf has the same depth.

(Our

definition of a balanced 2,3 tree coincides with the usual definition of a 2,3

tree.)

In the case of equal-weight items, a2, btree isbalancedif and onlyif it is biased; if all weights are one, the rank of anode isits heightinthetree.

Our first results show that biased 2, b trees have ideal access time for all items.

If xis a node,let

w(x)

be the totalweight ofthe items inleavesthat are descendants of x; that is,

w(x)

equals wiifx is a leafcontainingitem i, and

w(x)

equals

Y {w(y)ly

is a child of

x}

ifx is an internal node.

LEMMA 1. For any nodex, 2sx)-_-<

w(x). If

x isa leaf, 2s<x)-<

w(x) <

2x)+.

Proof.

Byinduction on

s(x).

Ifx is aleaf,thedefinition

s(x)=

Jig

w(x)J

implies

2’<= w(x)<

2x)/. If x is an internalnodewith a minorchild, x has amajorchild, sayy, thatis aleaf, and 2<’)- 2s<y)-<

w(y) <= w(x).

Ifx is an internalnodewith no minor children, x has at least two major children, say y and z, and 2s<x)-l=

2Y)-+2z-l<- w(y)+w(z)<=w(x). [3

LEMMA2.

If

X isa

leaf of

depth dcontaining item i, d

<

lg(W/wi)+2.

Proof

Let rbethe root ofthetree. Sincethe rankincreases byatleastonefrom child to parent,

d<=s(r)-s(x). By

Lemma 1, lg W=lg

w( r)

>-

s( r)

and lg

w(x)<

s(x)+

1. Combining inequalities gives the lemma. [3

THEOREM 1. A biased 2, b tree has ideal accesstime

for

allitems.

Proof

Immediate from Lemma2. [3

Inouranalysis oftherunningtimesof theupdate operations on biased2, b trees, we shall use amortization. That is, we shall average the running time ofindividual update operations over a

(worst-case)

sequence of updates. In order to make the analysis as concrete as possible, we introduce the concept ofcredits

(called

chips in [7],

[8]).

A credit represents one unit of computing time. To perform an update operation, weare given.acertainnumber ofcredits. Spending one credit allows us to perform

O(1)

computational steps. Ifwe completethe operation before running out ofcredits, we can save the extracredits to use on future operations. Ifwe run outof credits before completing the operation,we can spend previouslysaved credits. Ifwe canperformasequence of operationswithoutrunningoutofcreditsduring the process,

Downloaded 10/24/14 to 143.107.45.106. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

(5)

then the number ofcredits allocated to each operation gives an upper bound on its amortized runningtime.Wecall thisupper bound theamortizedtime ofthe operation.

Noticethatif thisanalytical techniqueissuccessful,then any sequenceofupdate operations requiresactual time at most a constant timesthesumoftheamortized times ofthe individual operations; a later operation may require more actual time thanits amortized time, but only if a corresponding amount of time was saved in earlier operations. Some algorithms, such as the path compression method of maintaining disjointsets [31], exhibitthe opposite behavior: early operations can be slower-than- average but onlyifthetime lostis made up in later operations.

Inthecase ofbiased2,b trees,weshallkeep track ofcreditssavedfromprevious operationsby storing theminthetrees. Inparticular,wesay a biased2,b tree satisfies thecredit invariant ifeveryminornode ywithparent xcontains

s(x)-

s(y)- credits.

(See

Fig.

1.)

Notethatthisdefinition is consistent with amajor node havingnocredits;

in particulara single-node treeneeds no credits. Foreach update operation we shall give an upper bound on the number of credits needed to perform the operation, assuming that the initial trees satisfy the credit invariant and requiring that the final trees satisfy the invariant. It is important to remember that the credits in a tree are onlyaconceptual deviceto aidinthe runningtime analysisand neitherappearinthe data structure noraffecttheactual implementation of the update algorithms.

We first consider (two-way) join, since all the other update operations can be defined in terms ofthis one.We shalldescribe an algorithm that joins twotrees with roots x and y andreturns the rootof the resultingtree. The algorithmis recursiveand consists ofthreemain cases, two ofwhich are symmetric

(see

Fig.

2).

to)

x

(b)

l/kxx,.

/

(c)

Z

FIG.2. Joinalgorithmforlocallybiased2, btrees. Triangles denotesubtrees.(a) Case (terminate). (b) Case2(recurse).Joinright child uofxtoy, formingv. (c)Subcase2a(vhasrank less thanx).Attach vas rightchildofxinplaceofu.(d)Subcase2b(vhassamerankasx).Attach childrenofvaschildrenofx.Split

xifithasmorethan b children.

Case I.

s(x)=

s(y), or

s(x) >

s(y) and x is a

leaf

or

s(x)

< s(y) and yis a

leaf.

Create and return a newnodewith nodes x andy as its two children.

Case 2.

s(x)>

s(y) and x is nota

leaf.

Let u be the right child of x. Remove u

as a child of x and recursively join the trees with roots u and y, producing a single tree, saywith root v.

Downloaded 10/24/14 to 143.107.45.106. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

(6)

550 S. W. BENT, D. D. SLEATOR AND R. E. TARJAN

Subcase 2a.

s(v)<= s(x)-

1. Attach v asthe right childof x and return x.

Subcase 2b.

s(v)= s(x).

In this case v has exactly two children. Attach these as children of x

(to

the right of the other childrenof

x)

and destroy v. Node x has now gainedachild. If xnowhas no more than b children,return x. Otherwisesplit xinto two nodes with

[(b+ 1)/2J

and

[(b+ 1)/2]

children, respectively. Create anew node w with these two nodes as children and return w. The two nodes resulting from the split have the same rank as x; the rankof w is one greater.

Case 3.

s(x)<

s(y) andy is not a leaf. This caseis symmetricto Case2.

Note. Whennode xissplitinSubcase2b,it isnotnecessaryto divideits children approximately fifty-fifty; it is sufficient that each new node have at least two children.

The first thing we must verify about this algorithm is its correctness. An easy inductionargument shows thatthe algorithm producesa2, btree whose roothasrank max

{s(x),

s(y)} or max

{s(x), s(y)}+

1; in the latter case the root has exactly two children. This verifiestheassertion at thebeginning of Subcase2b.Asimilar induction based on the following observations shows thatthe algorithm produces abiased 2, b tree given twobiased 2, b trees as input:

Case 1. Ifx is minor inthenewtree, y is aleaf, which means thatthe new tree is locallybiased at x; similarlyify is minor.

Subcase 2a. If v is minor in the new tree, u was minor in the old tree and the old left sibling ofu,which is nowtheleft sibling of v,is amajorleaf,givinglocal bias at v. On theotherhand, if theleft sibling ofv is minor in the newtree, it must bethe casethat u is a leafof rank

s(x)-

1.ButthenSubcase2bwouldhaveoccurredinstead ofSubcase 2a. Thus the new tree islocallybiased.

Subcase 2b. If the left child of v is minor, the right child of v is a leaf, which can only happenif the children ofv are u and y and the latter is a leaf. If the left sibling ofu inthe old treeis minor, u is aleaf of rank

s(x)-

1, and in this case also thechildrenof v are u andy. It followsthat the tree existing after x gains a childbut before x splits is locally biased. Splitting preserves local bias, which means that the finaltree is locallybiased.

Thusthe join algorithmis correct. We shall prove by asimilar case analysis that if we allocate

Is(x)-s(y)l+

credits to the join, we can perform the join while preserving thecreditinvariant. Thus the join requires

O([s(x)-s(y)l)

amortized time.

To carryoutthe analysis,we assume

s(x)>=

s(y). (Thecase

s(x)<

s(y) issymmetric.) We begin the joinwith s(x)-s(y)+ credits inhand.

Case 1. We need one credit to build the new tree and s(x)-s(y) credits to establish the credit invariant ony, foratotal ofs(x)-s(y)+1.

Case2. We acquire

s(x) s(u)

credits fromu,givingus atotal

of2s(x)

s(y)

s(u).

Weneed max{s(u), s(y)}-min

{s(u), s(y)}+

to recursivelyjoin thetreeswith roots u and y.

Subcase2a. Weneedone credit tobuild thenew tree and

s(x)- s(v)-

toplace on v.Ifs(y)

>= s(u),

weuse atotal ofs(y)-

s(u)+ s(x) s(v)+

<-

2s(x)

s(y)-

s(u),

since

s(V)

>-s(y)and

s(x)

> s(y).Ifs(y) <

s(u),

weuse

s(u)-

s(y)+

s(x)- s(v)+

<-

2s(x)

s(y)-

s(u),

since

s(x)

>

s(u)

and

s(v) >= s(u).

Subcase 2b. We need one credit to build the new tree. We need no credits to place on the new children ofx, since as children of v they alreadyhave the proper number ofcredits. Splitting x preserves the credit invariant.

(Local

bias implies that both nodes resulting from the split have rank

s(x).)

Thus, we use a total of max

{s(u),

s(y)}-min

{s(u),

s(y)}+2 credits. The analysis in Subcase 2a showsthat this is at most2s(x)-s(y)-s(u).

Downloaded 10/24/14 to 143.107.45.106. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

(7)

Summarizing ouranalysis, we have the following theorem:

THEOREM 2. The two-way join algorithm is correct and runs in

O(Is(x)-s(y)l)

amortizedtime on two treeswith rootsx and y.

There is ausefulalternativeformulation ofthistheorem. Wesay atree with root x is cast to rank kif it satisfies thecredit invariant andhas k-

s(x)

additional credits on its root. If x and y arethe roots oftwo trees cast to a rank k>max

(s(x),

s(y)}, thenTheorem2 implies that we canjoin thesetrees usingno extra credits, producing

a

singletree cast torank k.

Wecandescribethebehaviorofthejoin algorithmasfollows

(see

Fig.

3):

Traverse the rightpath of thetreerootedatx andtheleft path ofthe treerootedaty concurrently, descendingrank-by-rank,until arrivingat aleafin onepathor at two nodes ofequal rank, one in each path.

Merge

the traversed parts of the paths, ordering nodes in decreasing order by rank. If the traversal stops at two nodes of equal rank, say k,

FIG.3. Ajoin. Only rightpathof left tree,leftpathofrighttreeareshown. Numbers beside nodesare ranks. Node indicatedbyarrowiscreatedbyjoin.

eithermakethembothchildrenof the previous nodeonthemerged path,if theprevious node has rankk/1,orelsemakethem childrenofanew node with rankk/l, whose parentis the previous node. Starting from thebottomofthemergedpathandworking up towardthe root, split nodes as necessaryuntilreaching anodewith no more than b children. This description implies the followingworst-case time bound forjoin:

THEOREM 3. Considerajoin

of

twotreeswith rootsx and ysuchthattherightmost

leaf

descendant

of

x is u and the

leftmost leaf

descendant

of

y is v. The worst-casejoin

time is

O(max {s(x),

s(y)}-max{s(u),

s(v)})

O(log W/(w_

+ w+))),

whereWisthe total weight

of

the items in the newtree, w_

w(u),

and w/

w(v).

Note. The worst-case time for a join can be either larger or smaller than its amortized time.

Letus now considerthe otherupdate operations, beginningwiththree-way join.

Wecan implementathree-way joinas two successivetwo-way joins. Theorems 2 and 3 givethe followingtimebounds:

Downloaded 10/24/14 to 143.107.45.106. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

(8)

552 S. w. BENT, D. D. SLEATOR AND R. E. TARJAN

THEOREM 4. Consider the three-wayjoin

of

a tree with rootx to a leafy andto a tree withrootz. The amortizedtime

for

thejoinis

O(max {s(x),

s(y), s(z)}-min

{s(x),

s(y),

s(z)}).

The worst-case time

for

the join is

O(max {s(x),

s(y), s(z)}-s(y))- O(log (W/wi)), where Wis thetotal weight

of

the items in thenewtreeand istheitem

in node y.

Note. The worst-casejoin time is the same as the access time for item in the newtree and never exceeds theamortizedjointime.

Asplitcanbe implementedas asequence of(two-way)joins. Letusfirstconsider splitting at an item already in the tree. Let x be the rootof the tree to be split and ythe leafcontainingitemi.Thesplitwillproceedupthepath from ytox,accumulating a

left

tree of items less than and a right treeofitems greaterthan i. Initiallyy is the previousnode,theparent of yisthe currentnode, andthe left andrighttreesareempty.

The split consistsof repeatingthe following general stepuntil the root is the previous node

(see

Fig.4):

General step. Delete every child of the current node to the left of the previous node. If there is one such child, join it to thelefttree; ifthere are two or more such children, give them a new common parent and join the resultingtree to theleft tree.

Repeat this process with the children to the right of the previous node,joining the resulting tree to the right tree. Remove the previous node as a child ofthe current node and destroy it if it is not y. Make the current nodethe new previous nodeand its parent the new current node.

LEFT RIGHT TREE TREE

uO NEWPREVIOUS NODE

ufz2

LEFTTREE RIGHTTREE

NEW NEW

LEFT RIGHT

TREE TREE

FIG.4. Onestepofsplit algorithm.Nodeu isthecurrentnode,vthe previousnode,u,u2, the children

ofu,q therootofthetreethatisjoinedtothelefttreeand therootofthelefttree.

This algorithm is obviously correct. To establish its amortized time, let u bethe currentnode, v the previousnode, q therootof thetree containingchildren ofuthat isjoinedtothe left tree, and theroot of the lefttree.

An

easyinduction shows that

s(v) >-s(l).

Supposewebegin the current execution of the general step withboththe left and the righttree cast to rank

s(v)/

1. The following argument shows thatwith

2(s(u)-s(v))/

5 additionalcredits, we cancarry outthe general step andfinish with boththe left andthe righttree cast torank

s(u)/

1.Ifweplaceat most two new credits on q and

s(u)-s(v)

new credits on l,we canjoin q and to produce a newlefttree cast to rank

s(u)+

1, since either

s(q)= s(u)

(if u has two more children to the left

Downloaded 10/24/14 to 143.107.45.106. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

(9)

of

v)

or s(q)<-s(u) and q has s(u)-s(q)-1 credits on it already (if u has one child tothe left of

v).

Similarlyweneed

s(u)-s(v)+2

credits fortheright join. One new credit accountsfor the

O(1)

timerequired forthe restof the general step, giving atotal credit countof

2(s(u)-s(v))+5.

Summing overall executions ofthe general step,we obtain:

THEOREM5. The amortizedtime tosplita treewithrootxatleafyis

O( s(x) s(

y) O(log

W/

wi)), whereWis theweight

of

alltheitems in the treeand istheitem in

leaf v.

Each

o.f

the (up

to)

threeresulting trees is cast to rank

s(x)+

1.

Splittingatan item not in the tree isjustlikesplittingat anitem inthe tree, except that the initial execution of the general step is slightly different. Let x be theroot of the tree, an item not in thetree, i-and /thelargest item in thetree lessthan and the smallestitem inthe treegreater than i, respectively. And lety bethe handle of i, which is defined to be the nearest common ancestor of the leaves containing i- and

+.

Tosplit the tree, we combine all childrenof y containingitems smaller than i; the result becomes the original lefttree. We combine the remaining children of y

(those

containingitems greater than i) to form the original right tree. Then we make y the previous nodeand itsparent thenew currentnode and repeat the general stepasbefore.

THEOREM 6. The amortized time to splita tree with rootxat an item not in the tree is O(s(x)-s(y))-O(log(W/(wi-+wi/))), wherey is the handle

of

i, and i-, +

are as

defined

above. Each

of

the (up

to)

two resulting trees iscast to rank

s(x)+

1.

Unlikejoin, split does not have a logarithmic bound on its worst-case running time.

However,

as we shallsee atthe end ofthis section,we cangetagood boundon the worst-case split time by strengthening the bias property and changing the implementation of jointo maintain this stronger property.

Wecan implement each of the remaining update operations as acombination of a split and a join: an insertion is a two-way split followed by a three-way join, a deletion is a three-way split followed by a two-way join, and a weight change is a three-way split followed by a three-way join. The next theorem gives the amortized time of these operations.

THEOREM 7. The amortized time toperform an insertion

of

item into a tree is

O(log W’/min{wi-+wi/,wi})), where

W’

istheweight

of

thetree

after

theinsertionand

i-and +arethe largestitemsmaller than and thesmallestitemlargerthan i,respectively.

The amortized time toperform a deletion

of

item

from

a tree is O(log(W/wi)), where Wis the weight

of

the tree

before

the deletion. The amortized time toperform a weight changeonitem ina tree isO(log(max{

W,

W’}/min{wi, w})), where

W, W’,

wi,

w’i

are the weights

of

the tree

before

and

after

the updateand the weights

of before

and

after

the update, respectively.

Proof

Consider an insertion. The two-way split takes amortized time

O(log (W/(wi-+ w/)),where Wisthe weight of the original tree, andproducestrees cast to a rank of at least [lg(max {w-,

w/})J.

The three-way join thus requires O(log (W’/min {wi-/w/,

w}))

additional amortized time. This gives the bound for insertion,since W<-

W’.

Thethree-way split beginningadeletion requires O(log

W

wi)

time; the two-way join completingit takes

O(1)

additional amortized time since the treesresulting from the splitare cast tothesame rank. Thisgivesthe bound for deletion.

The three-way split beginning aweight change also requires O(log

W

wi) amortized

timeandproducestrees cast to a rankofatleast Jig

wJ.

Thethree-way join completing the weight change thus requires O(log

(max {W,

W’}/min {w,

w}))

additional amort- ized time. This gives the bound for weight change. q

Remark. In practice it may be useful to design customized implementations of insert, delete and weight change, rather than expressing them in terms ofjoin and

Downloaded 10/24/14 to 143.107.45.106. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

(10)

554 S. W. BENT, D. D. SLEATOR AND R. E. TARJAN

split. We leave this as a (nontrivial) exercise; the algorithms so obtained are more complicated than those using join and split.

The data structure we have described and analyzed is a good one if amortized runningtime isthecomplexitymeasureofinterest.Weshall now describe a modification appropriate ifworst-case per-operation running time is important. A globally biased 2,b tree is a 2, b tree with the following property, which is stronger than local bias

(see

Fig.

5)"

Globalbias.

Any

neighboring leaf ofa minor node y with parent x has rank at least s(x)-1. (We say thetree is globallybiased aty.)

Io

FIG. 5. A globallybiased2,3 tree. Weightsareinsideleaves,ranksaretoleft ofnodes.

Sinceanygloballybiased2, b tree islocally biased, globallybiased2,b trees have ideal access time. The following version ofthejoin algorithm willjoin two globally biased2,b trees with roots x andy into a single globallybiased 2,b tree andreturn the root ofthe new tree. (See Figs. 2 and 6.)

(a)

(b)

ECESSARY)

(C)

CESSARY)

FIG. 6. Case4ofglobaljoinalgorithm(equal ranks, nonterminating).(a) Right childofx, leftchildof

yjoinedtoformz.(b)Rankofzless thanx. Attachzasright childofx,fusex andy, splitifnecessary.(c)

Ranksofz andxequal.Fusex, z,y" splitifnecessary.

Case 1.

s(x)>=

s(y) and x is a leaf, or s(x)<-s(y) andyis a

leaf.

Create a new

node u with nodes x andy as its two children and return u.

Case2.

s(x)

> s(y) and xisnot a

leaf.

Proceed as inCase2ofthejoin algorithm for locally biased trees.

Case 3.

s(x)

< s(y) and yis not a

leaf.

Symmetric to Case2.

Downloaded 10/24/14 to 143.107.45.106. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

(11)

Case 4.

s(x) s(y)

andneitherxnoryis a

leaf.

Let u be therightchildof xand

v the leftchild of y. Remove u as achild ofx and v as a child ofy. Recursively join the trees rooted at u and v, producing a single tree, say with root z. If

s(z)<s(x),

attach z as the right child of x; otherwise

(s(z)= s(x))

attach the two children of z as (right-most) children of x and destroy z. Fuse x and y into a single node. If this newnode has no more than b children, return it; otherwisesplit it andreturn a new node whosetwo children are theresults of the split.

We shall refer to the join algorithm for locally biased trees as localjoin and to the version for globally biased trees as globaljoin. We can describe a global join iteratively as follows

(see

Fig.

7):

Traverse the right path of the lefttree and the left

io

FIG. 7. Aglobaljoin. Nodesonspliced pathmustbe splitifnecessary,workingbottom-up. Nodeindicated byarrow isformedby fusingtwonodes, onefromeachtree.

path of the right tree concurrently, descending rank-by-rank until reaching a leafin one ofthe paths.Mergethetraversedparts ofthepaths,ordering nodes indecreasing order by rank and fusing any two nodes ofequal rank. If the traversal stops at two leaves of equal rank, say k, do not fuse them but instead either make them children ofthe previous node on the spliced path,ifthe previous node has rank k

+

l, or else make them childrenofanewnode withrankk/ whose parentisthe previous node.

Proceed back up the merged path, splitting every node withmore than b children.

Aswith alocal join,aglobaljoin oftreeswith roots xandyproduces a2, b tree whose root has rank max

{s(x), s(y)}

or max

{s(x),

s(y)}+l; in the latter case the root has exactly two children. The following discussion shows that the new tree is globally biased. Let the

left

tree and the right tree be the original trees with roots x

and y, respectively. Considerthetreeproduced by applying the globaljoin algorithm without doing any splitting. We call this the

fused

tree. The only possible nodes at whichthe fusedtree might notbe globallybiased are minor nodes along the spliced path; let v with parent u be such a node. Node v has leafdescendantsin either the left tree, the righttree, orboth; is either anode, say q, in the left tree, anode, say r,intheright tree, anodeproduced by fusingtwonodes,say q from the lefttree and rfromtheright tree,or anewnodewith two children

(at

least oneofwhich is aleaf),

Downloaded 10/24/14 to 143.107.45.106. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

(12)

556 S.W. BENT, D. D. SLEATOR AND R. E. TARJAN

say q fromthe lefttree and r from the right tree. If q exists, its left neighboring leaf in the left tree has rank at least

s(u)-1

and isthe left neighboring leafof v in the fusedtree. Similarly if r exists, its right neighboring leafin the righttree has rank at least

s(u)-1

and isthe right neighboring leafof v in the fused tree. Supposeq does not exist. Then vis a minornodeinthe righttree.Letgwithparent

f

be the nodeon therightpathof thelefttreesuch thats(g)<-

s(v) < s(f).

(Ifg does not exist thefused tree isgloballybiased at

v.)

Then

s(u)<=

s(f),whichwhen combined withthefact that v is minor

(s(v)+

<

s(u))

implies thatg is minor in thelefttree.Thustheneighboring leaf ofg, which isthe neighboring leaf ofv inthe fused tree, hasrank atleast

s(u)-

1.

A similar argument applies if r does not exist. Thus in any case the fused tree is globallybiased at v. Splitting preserves global bias; thus the tree resulting from the join is globally biased.

THEOREM 8. Theglobaljoin algorithm is correct. Furthermore theworst-case time boundgiven in Theorem 3

for

localjoin holdsalso

for

globaljoin. Thusaglobaljoin runs

in O(log(W/(w_+ w/))) worst-case time, where Wisthe total weight

of

both trees, w_

is the weight

of

the rightmost item in the

left

tree, and w/ is the weight

of

the

leftmost

item in the right tree.

Proof.

The discussion above verifies correctness;thetimebound followsimmedi- ately.

TrEOREM 9. A three-wayjoin

of

globally biased 2, b trees, implemented as two successive globaljoins, has the same worst-case time bound as given in Theorem4

for

three-waylocal join. Thusa three-wayjointakes O(log W/wi)) worst-case time, where Wis the total weight

of

thejoined treeandwi is the weight

of

the item insertedbetween

thetwo trees.

Proof.

Immediate fromTheorem 8.

Wecansplitagloballybiased2,b treeexactlyas we didalocallybiased2,btree, using localjoins rather than global joins to build up the left tree and the right tree generated by the split. Below we shall verify that this method results in a globally biased tree, and alsoget a bound onthe runningtime of the operation. Let u be the currentnode, v the previous node, q the root of the treecontaining the childrenofu that are to be joinedto the left tree, and the root of the left tree.

(See

Fig.

4.)

The analysis is simplified by the assumption that the subtrees rooted at q and are not emptyand v is not aleafin the originaltree.

We want to verify by induction that after the entire split the resulting left and right trees are globally biased. The.induction hypothesis is that the leftmost path descending from is in theoriginaltree (exceptpossibly for itself), andthatthe tree rooted at isgloballybiased. Thetree with root q isgloballybiasedby construction, and its rightmost path (possibly excluding the node q itself) is apath in the original tree. Since v is not a leaf in the original tree, its left sibling cannot be minor. This implies that s(q)=

s(u)-

ors(q)=

s(u).

We knowby the earlier discussionofsplit that s(l)<-_

s(v) < s(u).

Combining these inequalities gives s(l)<-s(q).Thejoin of the trees with roots q and proceeds down the rightmost pathfrom q until reaching the firstnode such that is aleafor

s(t)

-<_s(l). Becauseofglobal bias, each nodeabove is major, and must also be major unless is aleaf. Thus the rank’ decreases by each step down the tree,and either

s(l)= s(t)

orone of or is aleaf.

(The

important point is that thejoin does not continue down the left-most path of as it normally might.) Atthis point and become siblings, and thejoin terminates

(after

splitting nodes back upthe mergedpath). We can nowverify thatourinduction holds for the new left tree just created. The leftmost path of this tree is that of the original tree exceptpossibly for thetop node(which is new only ifs(q)=

s(r)).

Wehave already

Downloaded 10/24/14 to 143.107.45.106. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

(13)

saidthat thenodes above mustbe major. The othernodes onthe original rightmost path descending from q also have global bias because they have the same adjacent leafonthe rightthatthey usedto have, namely the leftmost leaf of

I.

Thisshows that thenew lefttree is globallybiased.

It also follows from this discussionthat the number of steps takenby the join is O(s(q)-s(l)), because

(as

mentioned

above)

thejoin only traverses down the right path ofq until it reaches t.

(It

does not then propagate down the leftpath ofl.)

To obtain a time boundfor split, let us consider thejoins that form the left tree.

Letq,q2," qk betheroots ofthesuccessive treesjoinedintotheleft tree, let ui for

<-k bethe currentnode when thetreewith root qi isjoinedwiththe left tree, let

l

for ik be root of the left tree after the tree with root q is joined

(thus

l-ql), and finally let x be the root of the tree to be split and y the node at which the split starts. The discussion above implies that

s(q)-s(l)<-_s(ui) s(u+) -

s(q+)<-

s(u+)

for i-k- and that thejoin of thetrees with roots q+l and

li

takes O(s(q+)-s(l))time for <_- i<-k 1. For2<_-i<-_k l,thisboundis

O(s(u+l)-s(u))

by the inequalities above. Consider the case i-1 We have

ll-

ql.

If

s(

q)>-

s( u)

l, then s(q2)-S(ll)<-S(UE)-S(U)+1. Ifs(q)<s(u)-l,then q is aminor childoful, andtherightmostleafdescendant ofq2hasrank at least

s(ul)-

1.

Thus thejoin of trees with roots q and q2 takes O(S(qE)-S(U))=

O(S(UE)-S(U))

time. We conclude that for <-ik-l, the join of trees with roots

li

and q+ takes

O(s(u/)-s(u))

time. Summing over i, weobtain abound of O(s(x)-s(y)) onthe total timeto form the lefttree. The same argument appliesto the righttree. Thus we have the following theorem"

THEOREM 10. The worst-case time to split a globally biased 2, b tree rooted atx, starting at a node y, is O(s(x)-s(y)).

If

y is a

leaf

containing item i, the time is

O(log(W/w)).

If

y is an internal node, the time is O(log(W/(w_+w+))), where w_

and

w+

aretheweights

of

theitems inthe

left

andright neighboring leaves

of

y, respectively.

If we implement each of .the operations insert, delete and reweight as a split followed bya global join,we obtainfromTheorems 8-l0the followingtime bounds"

THEOREM 1. Theworst-casetime to insertan item into agloballybiased2,btree isO(log

W

wi_

+

wi+))

+

log(W’/wi)), wherethevariousparameters are

defined

as in

Theorem7. The time to delete an

ite.m

is O(log(W/w)+log(W’/(wi_+wi+))). The time tochange the weight

of

an item is O(log (W/wi)+log(W’/w)).

Remark. Based on thetimebounds we have derived, thechoice between locally andgloballybiased treesdoesnot seem to beclear-cutbutdependsupon the application.

We concludethis sectionby describing awaytobuild a globallybiased2, b tree ofn items in

O(n)

time. The idea is toform n single-leaf trees, oneper item, and join themone-at-a-time, left-to-right,into alarge tree, initially empty. Tojoin asingle leaf x withthe currenttree, we use abottom-up method. Westart atthe rightmost leaf of theIf vtree and walkis the tree root,upuntilwe create a new root with twofinding themaximum-ranknode,children, vsayv,such thatand x, and

s(v)

stop.

- s(x).

Ifv is notthetree root, we compares(p(v)) to

s(x).

Ifs(p(v))-

s(x)+

l, we make x the rightmost child ofp(v) and split nodes up the right path as necessary. If s(p(v))>

s(x)+

l, we create a new node with two children, v and x, and replace v as a child ofits old parent by the new node.

(See

Fig.

8.)

Thisbottom-up join method obviouslymaintains globalbias. To obtainabound onthetotal time for all n- joins,we note that, exceptfor

O(1)

time per join, each step taken by ajoin either decreases the numberof nodes on the rightmost path of the current tree or splits a b-node

(a

node with b children), thereby reducing the number of b-nodes by one.

A

singlejoin can only increase the number of nodes on

Downloaded 10/24/14 to 143.107.45.106. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

(14)

558 S. W. BENT, D. D. SLEATOR AND R. E. TARJAN

’9 ATTACH \ SPLIT

FIO.8. Bottom-upjoinofasingleitemwith agloballybiased2, 3 tree.

the rightmost path by one and can only increase the number of b-nodes by one. It follows that the n-1 joins require a total of

O(n)

time, and we have the following theorem:

THEOREM 12. Repeatedsingle-node, bottom-upjoins willconstructagloballybiased 2, btree in

O( n)

actualtime.

Note. Theorem 12 does not include time corresponding to the credits necessary to establish thecreditinvariant onthe constructedtree (ifwe are using locallybiased

trees);

the number of credits needed depends upon the relative weigh

t

ofthe items

and is notbounded byany function of n. (Considera tree containingtwo items with weights and 2k for k arbitrarilylarge.)

Remark. Localjoin and global joinas wehave described them each consist ofa top-down pass

(for

merging) followed by abottom-up pass

(for

splitting).

However,

if b

=>

4 eitherform of joincanbeimplementedin aone-pass, purely top-downfashion by preemptively splitting nodes with b or more childrenduring merging.

4. Biasedbinarytrees. Inpractice,implementations ofbalanced tree data struc- tures areplaguedbyamultiplicity ofcases, making the resulting codelengthy,opaque and hard to prove correct. Inthis section we shall describe a class ofbiased search trees whose update algorithms are relatively easyto program and have amanageable numberofcases.Weshall only sketchproofs of algorithmcorrectness and timebounds, since theproofs use exactly thesametechniques asin 3.

A locallybiasedbinary searchtree is afull binary searchtree (everyinternalnode has exactlytwo children), each of whosenodes x has an integerrank

s(x),

suchthat the ranks have thefollowing properties"

(i) Ifx is aleaf,then

s(x)=

[lg

w(x)J.

(ii) If node y has parent x,s(y)<=s(x); ify is aleaf, s(y)<-s(x)-l.

(iii) If node y has grandparentx, then s(y)<=

s(x)-1.

(iv) Local bias.

A

node is minor ifthe rank of its parent is at least two greater than its own rank and major otherwise. Lety be a minornode with parentx. If y is the left child of x, either the sibling of y orthe left child ofthat sibling is a leaf of rank

s(x)-1.

If, in addition, x is the rightchild of its parent and has the same rank as its parent, theneitherthe sibling ofx orthe right child of that siblingis a leaf of rank

s(x)

1.Asymmetricconditionholdsifyistherightchildofits parent.

(See

Fig.

9.)

9

I0

(4)

FIG.9. A locallybiased binarytree.

Downloaded 10/24/14 to 143.107.45.106. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

(15)

Biasedbinarytrees are a binarized versionofbiased2,4 trees; if wetakeabiased binary tree and condense into asingle node all adjacent nodes ofthe same rank, we obtain abiased2,4 tree.

(See

Fig.

10.)

Biasedbinarytreesgeneralize symmetric binary B-trees [5], which have been described as red-black trees [12]. In the case ofequal weights, we obtainthe red-black representation ofa biased binarytree by callingan edge red ifparentand child havethesame rank andblack if their ranks differby one;

in this case all nodes are major. Ifwe want to becolorful we can in thegeneral case call an edge blue if it joins a minor child with its parent; then we can call biased binary trees red, black and blue trees.

Ca)

FIG. 10. Correspondence betweenbiased2,4treesand biasedbinarytrees.(a) 2-node. Rankofnodeis

s.Rootsofsubtrees denoted by triangles haveranksless thans.(b)3-node. Thereare twopossiblebinarized

forms.(c)4-node.

Allthe theorems presentedin 3 for biased2, b trees holdforbiasedbinary trees, since we canregardbiasedbinarytrees asjustarepresentation ofbiased2,4 trees. In particular biasedbinarytreeshave ideal access time forall items.Intheremainder-of this section we shall give algorithms for joiningand splittingbiased binarytrees. The correspondence with biased 2,4trees is somewhat loose because there are two rep- resentationsofa 3-node.

We beginby presenting an algorithm for join. If x is a node, we denote the left child ofxby

l(x)

andtherightchildof x by

r(x);

ifx is aleaf,

l(x)-- r(x)=

null.

By

promoting anodewe meanincreasingits rankbyone. Thealgorithmuses twofunctions, tilt

left (x)

and tiltright

(x),

whosebehavior is asfollows:

tilt

left (x):

If bothchildren ofinternal nodex have the same rank as x, promote xand return x. Otherwise if theright butnotthe left childof x hasthesamerank as

x,

performasingle leftrotation atnode x

(see

Fig.

11)

and return the new parent of x

(the

old rightchild of

x).

Inall othercases merely return x.

tilt right

(x):

Symmetric to tilt

left (x).

RIGHTROTATION

FIG. 11. Asinglerotation atnode x.

Downloaded 10/24/14 to 143.107.45.106. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

(16)

560 S. w. BENT, D. D. SLEATOR AND R. E. TARJAN

Remark. If

x’

isthe node returned by tilt

left (x),

thenthe leaf descendants of

x’

in the new tree areexactly the leafdescendants of x in the old tree. Also,

x’

and its right child have different ranks. Achieving the latter condition is the purpose of the

tilt

left

operation.

The join algorithm consists of a function localjoin

(x,

y) that returns theroot of thetree formed by joiningthe trees with roots x andy. Thefunction localjoin (x, y) is defined by the following cases

(see

Fig.

12):

Case 1.

s(x)=

s(y), or

s(x)>

s(y) and x is aleaf, or

s(x)<

s(y) andyis a

leaf

Createand return a newnodewithleftchildx,rightchildyandrankmax

{s(x), s(y)} +

1.

Case 2.

s(x) >

s(y) and x is not a

leaf.

Replace x by tilt

left (x).

Let z be the

right child ofx. Definethe new right child ofxto be local join

(z,

y) and return x.

Case 3.

s(x)<

s(y) and y is not a leaf. Symmetricto Case2.

(a)

(b)

JOIN(x2,Y)

FIG. 12. Join algorithmforlocallybiasedbinarytrees. (a) Case 1. Terminate. (b) Case2 withx nota right-leaning 3-node. Promotexifxa4-node. Replaceright childofxbythe joinofthis childand y.(c) Case

2 with xaright-leaning 3-node. Rotateleftatx.Replace rightchildofrootbythe joinofthis childand y.

We canverify thecorrectnessofthisalgorithm as follows. Thefunction call local join

(x,

y) returns a treewhoseroothas rankmax

{s(x),

s(y)}or max

{s(x),

s(y)}+1.

FurthermoreifCase 2 occurs and apromotion takes place (whichhappens if

s(x)>

s(y), x is not aleaf,and

s(x)= s(l(x))= s(r(x))),

thenin thenextcall, which is local join

(r(x),

y), Case 2 also occurs but neither a promotion nor arotation takes place, by properties (ii) and (iii). Thus localjoin

(r(x),

y) returns a node ofrank

s(r(x)).

SimilarlyifCase3 occursandapromotion takes place, thenext call localjoin

(x,

l(y)) returns anodeof ranks(l(y)). It followsthat if theoriginalcall localjoin (x, y)returns anode,sayx,ofrank max

{s(x), s(y)}+

1, bothchildrenofz have rank lessthan

s(z).

An

inductive case analysis usingthis fact shows that localjoin is correct.

To establish a time bound for localjoin we canusethe same credit invariantfor biased binary trees that weused forbiased2,b trees; a count of credits as in 3proves Theorem2 for biased binary trees. Theorems3 and 4 for biased binary trees follow immediately. Although we have defined local join recursively, it is easy to give an iterative, purely top-down version. Weleave this as an exercise.

Wecan use the samesplit algorithmon biasedbinarytrees that weusedonbiased 2, b trees and the number ofcases is much reduced. To split a tree at a leaf x, we initialize v

(the

current

node)

tobex,and q andr (theroots ofthe leftandrighttrees, respectively) to be null. Then we repeat the following general step until v is theroot of the tree

(see

Fig.13), wherep(v) denotes the parent ofnode v:

Downloaded 10/24/14 to 143.107.45.106. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Referências

Documentos relacionados

Para a construção da combinação binária, bem como o cálculo do índice Kappa, a metodologia de ELISA foi utilizada como referência para classificar as amostras

Este problema sobre a existência de um tipo de arte para pessoas mais cultas (“artistas” nas palavras do autor) e um outro tipo de arte mais acessível para o público

Com base nessa realidade, apresentam-se os organismos/instituições que possuem meios aéreos para a realização de EA, sendo eles a Força Aérea Portuguesa (FAP), a Autoridade

Figure 4.9: The figure shows a graphic with the number of bytes per node ratio for a simulated tree, the same tree stored in a parentheses tree data structure, a simulated tree for

With this tree structure, we can traverse the tree and apply the rules to switch version and execute code on the right version. Listing 4.7 represents the relation in Figure 4.1,

In this case, the cohesive failure was characterized by an initiation zone where the failure looks similar to the fracture zones obtained for Mode II followed by

The authors believe that, a comparative analysis between the costs related to cascading use of wood (waste wood collection, separation and processing) and the costs for round wood

O e-detailing educa os Médicos a prescrever a marca pela persuasão e fidelização proporcionadas pelo manuseamento das novas ferramentas de marketing farmacêutico digital