algorithm - AVL tree rotation and red-black tree color flips -


as know, insertion , deletion require o(log n). avl tree require o(log n), because need o(log n) insert , o(log n) rotation balance.

rb tree require o(log n), because need o(log n) insert, in introduction algorithms third edition, rb-insert-fixup need o(log n) case 1(color flips), , @ 2 times rotation. seems avl require 2o(log n), rb tree require 2o(log n)+c.

why think rb tree more faster avl in insertion? because rotation need more time color flips? rotation , color flips both require o(1), why rotation more time-consuming color flips? thanks!:)

if understand question correctly, yes true rb-trees , avl-trees both offer lookup, insertion, deletion in o(logn) time.

avl-trees more rigidly balanced rb-trees. attain this, lot of rotations required, time consuming. rb-trees unbalanced, have weaker rules balancing, need lesser operations insertion , deletion. consequence, lookup in avl-trees faster rb-trees, insertion , deletion faster in rb-trees.

edit

please read this blog post. point rb trees balance faster avl trees after insertion. yes, rotation take o(1) time in avl trees, @ 2 rotations need done, point of rotation still needs found, , time rotation becomes o(logn). whereas in rb trees, rebalancing after insertion runs in amortized constant time. so, o(1) amortized time color flips, not o(logn).


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -