Question: use python to solve this problem Create a red - black tree data structure that implements each of the methods using the pseudocode from the
use python to solve this problem
Create a redblack tree data structure that implements each of the methods using the
pseudocode from the textbook included at the end of this document:
rbinsert
rblnsertFixup
leftRotate
rightRotate created in class
rbTransplant
rbDelete
rbDeleteFixup
printdraw the tree make sure you source where you got the method if you don't
create a custom one yourself
Insert the values shown in the RB tree below:
b
Explain why when you insert the values they do or do not look like the tree above. pseducode is down below Here is the text transcription of the pseudocode:
LEFTROTATET x
go
Copy code
y xright set y
xright yleft turn ys left subtree into xs right subtree
if yleft Tnil
yleft.p x
yp xp link xs parent to y
if xp Tnil
Troot y
elseif x xpleft
xpleft y
else xpright y
yleft x put x on ys left
xp y
RBINSERTT z
lua
Copy code
y Tnil
x Troot
while x Tnil
y x
if zkey xkey
x xleft
else x xright
zp y
if y Tnil
Troot z
elseif zkey ykey
yleft z
else yright z
zleft Tnil
zright Tnil
zcolor RED
RBINSERTFIXUPT z RBINSERTFIXUPT z
csharp
Copy code
while zpcolor RED
if zp zppleft
y zppright
if ycolor RED
zpcolor BLACK case
ycolor BLACK case
zppcolor RED case
z zpp case
else
if z zpright
z zp case
LEFTROTATET z case
zpcolor BLACK case
zppcolor RED case
RIGHTROTATET zpp case
else same as then clause with "right" and "left" exchanged
Troot.color BLACK
RBTRANSPLANTT u v
lua
Copy code
if up Tnil
Troot v
elseif u upleft
upleft v
else
upright v
vp upRBDELETET z
scss
Copy code
y z
yoriginalcolor ycolor
if zleft Tnil
x zright
RBTRANSPLANTT z zright
elseif zright Tnil
x zleft
RBTRANSPLANTT z zleft
else
y TREEMINIMUMzright
yoriginalcolor ycolor
x yright
if yp z
xp y
else
RBTRANSPLANTT y yright
yright zright
yright.p y
RBTRANSPLANTT z y
yleft zleft
yleft.p y
ycolor zcolor
if yoriginalcolor BLACK
RBDELETEFIXUPT xRBDELETEFIXUPT x
scss
Copy code
while x Troot and xcolor BLACK
if x xpleft
w xpright
if wcolor RED
wcolor BLACK case
xpcolor RED case
LEFTROTATET xp case
w xpright case
if wleft.color BLACK and wright.color BLACK
wcolor RED case
x xp case
else
if wright.color BLACK
wleft.color BLACK case
wcolor RED case
RIGHTROTATET w case
w xpright case
wcolor xpcolor case
xpcolor BLACK case
wright.color BLACK case
LEFTROTATET xp case
x Troot case
else same as then clause with "right" and "left" exchanged
xcolor BLACK
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
