2011.04.18-caracteristicas-de-uma-arvore-de-busca-binaria

Upload: andrws-vieira

Post on 08-Apr-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/7/2019 2011.04.18-Caracteristicas-de-uma-arvore-de-busca-binaria

    1/2

    ri .... t1i

    Binary Search Trees - RoteiroCaractersticas de uma rvore de busca binria rootlTI pinh lel lhe 1'001 of Iree T.Ench node contalls the tlelds h:.y (alld possibJy o/ht:l '

  • 8/7/2019 2011.04.18-Caracteristicas-de-uma-arvore-de-busca-binaria

    2/2

    o algoritmo TREE-SUCESSOR retoma o sucessor de um nodo x.10. Encontre os sucessores de 15,6,4 e 20 para a TREESUCCESSClR(.fl

    rvore da Figura 2. if NIL11. Se x a maior chave na rvore de busca thell l 'CtllnJ 'J R E f : A l I N I ~ r I I M ! r i g h r : x l ) binria, o que o algoritmo retoma? Y . - p!x i12. Se a sub-rvore direita de x no-vazia, o whih- y :cF NIL :md righr!vdo,\' y .. que o algortimo retoma? p!y 13. Se a sub-rvore direita de x vazia, o que o I 'ptul'n yalgortimo retoma?

    14. Construa o algoritmo TREE-PREDECESSOR o qualretoma o predecessor de um nodo x.15. Qual a complexidade de tempo dos algoritmos TREESUCESSOR e TREE-PREDECESSOR, para umarvore de altura h? Justifique.

    Figura 2Considere os algoritmos TREE-INSERT e TREE To illserl V:dllt I' imo rik' hnary ,Ir:lrl'il frITo ril IIDELETE. l'. I i ~ ! r i ,1 til L :llld NL16. Execute TREE-INSERT(T, C) para rvore

    da Figura 1. Esboce a -rvore aps a fREE-INSERTCL.r1 Y N1Linsero. x f{)OIIT17. O que os ponteiros x e y esto "rastreando" whikx :cF NIL no TREE-INSERT? d.. ;t' < - x 18. O algoritmo TREE-DELETE pode ser if keylz < fhel! xquebrado em 3 casos: z no tem filhos, z tem ds e

    um filho e z tem dois filhos. O que o plzl algoritmo executa em cada um dos casos? ir y = NIL 19. Execute o TREE-DELETE para deletar a) thel! IvotiT! - z 'rret' T emplyd!'c ir kt'y! < key!vK, b) H e c) B da rvore da Figura I. then leftly - zIdentifique em qual dos 3 casos listados .:1St' riglul y ianteriormente o item se enquadra.TREE DELETE(T, =!Esboce a rvore resultante aps a r> Dorelrnine \ \ ' h J , , ~ h nUh: y tt ) "pli(:t;" i)IIT: \:i,lh:r:: 01' : : ' \ 'UU"!..'Y'.0r.deleo. if Icftizl = NII. ,I' h,,,er IQ a llon ..NII. hld of y, (n to !'lll. ir r I),,, !lU COilhh"lLTREE-OELETE para uma rvore ir 1 y Sl'lTIOved frolll l h ~ Ilee hy ! l l ( I l ) i p l J k ~ i l l l ~ ].l(lint,?!, oi' j.!ly] ;tlld ," \linimizing I'unnillg time j f x :F NIL thcn p!.x! plyl heo nllUling lime in tenns of h(lhe height of lhe binaJ'y se:u\:h if plyl NIL thn raori r I "" xill,tead "r I! Ohe l 1 u r n L ~ r o f in lhe ds ir y leftipl y I

    t lWIl lefil pl y li x$irch tree il Fl(,ll..-no belte! 111:In Jlked li)!. elSt' rightll'! y I! x Solulilln: '111illl ( b a l a n c ~ d lreelh O(lgl1), Ir il \Vi,tS z ~ s s u c c e S ~ l t r lh.1I \va:-: "plit'vd (lU!. l 0 f . l ~ il..: lbt;l jnil}::'.ir cF zIh"ll keylz key!yl

    copy y', "l1