Types of Trees - Data Structure and Algorithm | CSCE 221, Study notes of Computer Science

Types of trees Material Type: Notes; Professor: Leyk; Class: DATA STRUC & ALGORITHM; Subject: Computer Sci. & Engr.; University: Texas A&M University;

Typology: Study notes

2011/2012

Uploaded on 03/07/2012

josejlm2
josejlm2 🇺🇸

4 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1

Partial preview of the text

Download Types of Trees - Data Structure and Algorithm | CSCE 221 and more Study notes Computer Science in PDF only on Docsity!

Type of tree operation Running times Heights a ight of AVL tree Oflog n) Max Height of AVL tree <= 1.44 log(nodes+1) le restructure for AVL tree | O(1)__|_ Max Height of red-biack tree <= 2 log(nodes+1) All other functions Oflog ab Max height of 2 4 Tree <=loginodes +1) Height of 24 Tree Otlog n) Loga(n+4) -1 <=PBT<=(n-4)/2 Insertion of 2 4 Tree Ollog a) exper fer! Hof duicusort ice al Deletion of 24 Tree ‘Ollog a) a BT worst case Ola) BT best case ‘O(log a) Balance factor = (left height - right height) AVL tree of height h has at least F(h)+3 ~ 1 where fis Fibonacci sequence FO) = 0, F(2) = Land F(i) = F(i)-1+ Fli)-2 fori2 24 grease i oan right rotation single: BinaryNode Y = X >left; ¥ x z X-pleft = Y->right; Y-pright = X; return Y; : a « ', 7 + = Doubleright: X->left = singleLeft(X->left); return singleRight(X); ’ x € a ea a # ¢& 9-4 trees: search path never exceeds c log? (n +1) = = =. a a 8 le = nt; e<=44h; a>=24h owas = ee red/black: O(n) worst case. Height O(log2 n). black height- number of black Sy x a : ~~ fades on path eo ae ion:O(1), insertion:O(logn) rules: inserted node is always red. Root is always black. If there are two red nodes in a row after insertion, check the parent's sibling. Case1: when the parent of inserted node is red and the parant’s sibling is also red. granpas is black. Recolor parent and parent's sibling black and grandparent red. Check for new red/red violation. At great granpas case2,3: when parent of inserted node is red and parent sibling is black. In case 2, inserted node is right child, in case 3 iLis left one. For case? move x Lo left child (case3). Parent and grandpa swap colors and the segment rotates right in respect to grandparent. Left-image is case2zinto3, right image is both 9 Pp S..... © oS... @ @’ "gon e e e © oe ¢ aw casel: Oflogn), case2,3: O(1), total of insert is O(logn) AVL: find, put,erase:0(logn), singlereconstruction:0(1) Height: O(logn) 2-4: Insertion,deletion:O(logn)Height:0(logn}. Red-black: insertion:O(logn)HeightO(logn) € Properties: . mw oe=itl mo on=2e-1 ® — Notation m ohsi n number of nodas mm hs(n-4)/2 e number of external nodes . gar i number of internal nodes B hzlope h height B h2log,(n+t)-4