From 99508f70168660ecebaf752b4daf790670322efe Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Thu, 22 Aug 2013 17:56:17 +0100 Subject: [PATCH] further improvments on the rb examples --- docs/rbdelete.txt | 96 +++++++++++++++++++++++++++++++++++++++++++++++ docs/rbinsert.txt | 5 ++- 2 files changed, 99 insertions(+), 2 deletions(-) diff --git a/docs/rbdelete.txt b/docs/rbdelete.txt index 071d2e4..b0803b6 100644 --- a/docs/rbdelete.txt +++ b/docs/rbdelete.txt @@ -146,4 +146,100 @@ exchange colors of P and S and make Sr black. B(N) B(N) B(N) B(N) B(N) B(N) B(N) B(N) + + +now for case 2, we delete 16 from the following tree + + B(13) + + R(8) B(16) + + B(3) B(11) B(N) B(N) + + B(N) B(N) R(9) B(N) + + B(N) B(N) + +again first lets see what we have where... + + N : Nullpointer set in R(13)->right (thus N will be black by definition, ever) + P : B(13) + S : R(8) + Sl: B(3) + Sr: B(11) + + B(13)P + + R(8)S B(N)N + + B(3)Sl B(11)Sr + + B(N) B(N) R(9) B(N) + + B(N) B(N) + +revert colors of P and S + + R(13)P + + B(8)S B(N)N + + B(3)Sl B(11)Sr + + B(N) B(N) R(9) B(N) + + B(N) B(N) + +rotate right at P + + B(8)S + + B(3)Sl R(13)P + + B(N) B(N) B(11)Sr B(N)N + + R(9) B(N) + + B(N) B(N) + +relable ... done on wikipedia (don't know if I will need it.) + + B(8) + + B(3) R(13)P + + B(N) B(N) B(11)S B(N)N + + R(9)Sl B(N)Sr + + B(N) B(N) + +ok, not case 3... P is red +nor is it case 4 Sl is red. +kind of case 6 reversed ... lets try what they do in the code not in the description... + +Sl to black + + B(8) + + B(3) R(13)P + + B(N) B(N) B(11)S B(N)N + + B(9)Sl B(N)Sr + + B(N) B(N) + +rotate right on P + + B(8) + + B(3) B(11)S + + B(N) B(N) B(9)Sl R(13)P + + B(N) B(N) B(N)Sr B(N)N + +This result is wrong....the balance is ok, but the color of 9 is wrong. + # vim: set et ts=4: diff --git a/docs/rbinsert.txt b/docs/rbinsert.txt index 728d7e1..12bae66 100644 --- a/docs/rbinsert.txt +++ b/docs/rbinsert.txt @@ -49,12 +49,13 @@ case 2 (black parent): add an element 8. B(13) - R(i8) B(N) + R(8) B(N) B(N) B(N) we violate none of the properties defined. Nothing to be done. + Now add 16 which is case 2 again B(13) @@ -195,7 +196,7 @@ before starting over again, we have the following: grandparent B(13) -now property 4 of for our new parnet is violated which brings us to case 4 as +now property 4 of our new parent is violated which brings us to case 4 as it is not the root. (the cases are taken from wikipedia.) so lets do case 4 on our node (which is left rotate on our parent,