10.07.2015 Views

Generic Red-Black Tree and its C# Implementation - The Journal of ...

Generic Red-Black Tree and its C# Implementation - The Journal of ...

Generic Red-Black Tree and its C# Implementation - The Journal of ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Mechanism for insertion into a red-black treePerform an ordinary binary search tree insertion into the red-black tree. If the path fromroot to the new leaf node that contains the information being inserted passes through anode that contains two red children, re-color these nodes black <strong>and</strong> re-color the node withthe two previously red children black, assuming that it is not the root node (if it is, leavethe node black since the root node <strong>of</strong> a red-black tree must be black).Color the new leaf node just inserted red.If the steps above lead to a succession <strong>of</strong> two red nodes in moving from the rootdown the tree, a rotational correction is needed. <strong>The</strong>re are four possible rotations that arepossible. Two <strong>of</strong> these are illustrated in Figures 2(a), (b). <strong>The</strong> other two are mirrorimages.Left rotate on N2 <strong>and</strong> color N1 red <strong>and</strong> N2 black.Figure 2a – Rotational <strong>and</strong> Recolor CorrectionVOL. 4, NO. 2 JOURNAL OF OBJECT TECHNOLOGY 61

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!