2-3-4 Trees
A variation on the B-Tree is a 2-3-4 Tree, which is a multiway tree in which all non-leaf nodes have 2, 3, or 4 children. Therefore:
Each node stores at most 3 values
Each internal node is a 2-node, 3-node, or 4-node
All the leaves are on the same level
Processing a 2-3-4 Tree
Searching is the same as with multiway search trees.
Insertion into a 2-3-4 Tree begins with a single node where values are inserted until it becomes full (ie. until it becomes a 4-node). The next value that is inserted will cause a split into two nodes: one containing values less than the median value and the other containing values greater than the median value. The median value is then stored in the parent node. It's possible that insertion could cause splitting up to the root node.
Insert the values 53, 27, 75, 25, 70, 41, 38, 16, 59, 36, 73, 65, 60, 46, 55, 33, 68, 79, and 48.
Inserting the 25 results in a split:
Inserting 38 causes a split:
Inserting 73 causes a split:
Inserting 46 results in a split that propagates up to the root:
Inserting 55 causes a split:
Deletion from a 2-3-4 Tree will always occurs in a leaf node.
If the value to be deleted is in a leaf node and that node is a 3 or 4-node, then deletion is simple - the value is removed and the node becomes a 2 or 3 node, respectively.
If the value to be deleted is in a leaf node and that node is a 2 node, then underflow occurs. Underflow is "fixed" by transferring a value from the parent node to the node where underflow occurs and transferring a value from a sibling that is a 3 or 4-node. If the node where underflow occurred doesn't have a sibling that is a 3 or 4-node, then fusion occurs. The fusion requires the underflow node become a 3-node that contains the value from the sibling node and the separating value from the parent.
If the value to be deleted is NOT in a leaf node, then it is replaced by its immediate predecessor and the predecessor value is deleted from the tree.
Storage
A 2-3-4 Tree can be stored in the same manner as a B-Tree, but for small amounts of data that isn't located on external storage devices it would be ideal to store the information as a binary search tree. The only thing that must be distinguished is whether values are contained within a 2-3-4 node or whether they are located in child nodes. Let links between value within a node be represented with red links and links between parent/child values be represented by black links. Therefore:
A 2-node:
results in
A 3-node:
results in OR
A 4-node:
results in
Red-Black Trees
This type of representation results in a Red-Black Tree, which is a binary search tree with two types of links/nodes, red and black, that satisfy the following properties:
black condition - every path from the root to a leaf node has the same number of black links/nodes
red condition - no path from the root a leaf node has two or more consecutive red links/nodes (ie. every red node will have a black parent)
the root is always black
The nodes in a Red-Black Tree might be represented as follows:
template
class RedBlackNode
{
public:
...
private:
T data;
char color; // 'R' if the incoming link is red, 'B' if the incoming link is black
RedBlackNode *leftChild, *rightChild;
};
Processing Red-Black Trees
Insertion
A value is inserted into the tree using the standard binary search tree algorithm, however a decision must be made as to whether it should be inserted as a red or black link/node. If the node is inserted as a black link/node, then the number of black links/nodes in the one path would increase, which would violate the black condition. Therefore the node will be inserted as a red link/node.
This could result in a violation of the red condition but that can be fixed by performing either a color change or a rotation. Three possible cases arise:
Case 1: If the parent node is a black node, then insertion is finished.
Case 2: If the parent node is a red node and the aunt/uncle node is black.
Case 2a: If the node was inserted into the left child of the left child of the grandparent, then the violation is fixed by performing a single right rotation.
Case 2b: If the node was inserted into the right child of the right child of the grandparent, then the violation is fixed by performing a single left rotation.
Case 2c: If the node was inserted into the right child of the left child of the grandparent, then the violation is fixed by performing a left-right rotation.
Case 2d: If the node was inserted into the left child of the right child of the grandparent, then the violation is fixed by performing a right-left rotation.
After all of the rotations, the parent node is made black and the child nodes are made red.
Case 3: If the parent node is a red node and the aunt/uncle node is red.
The parent and aunt/uncle nodes will be made black and the grandparent node will be made red. The exception to the grandparent becoming red is if the grandparent is the root of the tree - in this case it will remain black.
OR if 84 is the root, then
Fixing one violation of the red condition could cause it to propagate up the tree. The violations should be fixed until the root of the tree is reached.
2-3-4 ต้นเปลี่ยนแปลงบนต้น B เป็น 2-3-4 ต้น ซึ่งเป็นต้นไม้ multiway ที่โหนบัพทั้งหมดมี 2, 3 หรือ 4 เด็ก ดังนั้น:แต่ละโหนเก็บมากที่สุด 3 ค่าแต่ละโหนภายในเป็น 2-โหน โหน ด 3 หรือ 4 โหนดใบไม้ทั้งหมดอยู่ในระดับเดียวกันประมวลผล 2-3-4 ต้นค้นหาได้เหมือนกับค้นหา multiway ต้นไม้แทรกลงใน 2-3-4 แผนภูมิเริ่มต้นกับโหนเดียวที่มีแทรกค่าจนกว่าจะเต็ม (ie จนกระทั่งมันกลายเป็น 4 โหนด) ค่าถัดไปที่ถูกแทรกจะทำให้เกิดการแบ่งเป็นโหนสอง: หนึ่งที่ประกอบด้วยค่าน้อยกว่าค่ามัธยฐาน และอื่น ๆ ที่ประกอบด้วยค่ามากกว่าค่ามัธยฐาน ค่ามัธยฐานนั้นในโหนดหลัก มันเป็นแทรกอาจทำให้แบ่งไปโหนดรากแทรกค่า 53, 27, 75, 25, 70, 41, 38, 16, 59, 36, 73, 65, 60, 46, 55, 33, 68, 79 และ 48ใส่ 25 ผลลัพธ์ในการแยก:ใส่ 38 สาเหตุแบ่งเป็น:แทรก 73 สาเหตุแบ่งเป็น:แทรก 1 ผลลัพธ์ในแยกที่แพร่กระจายถึงราก:แทรก 55 สาเหตุแบ่งเป็น:การลบจาก 2-3-4 แผนภูมิจะมักจะเกิดขึ้นในโหนดสาขาถ้าค่าเป็นลบคือ ในใบโหนดและโหนเป็น 3 ตัว หรือ 4 โหน การลบแล้วจะง่าย- เอาค่า และโหนดที่เป็น โหน 2 หรือ 3 ตามลำดับถ้าค่าเป็นลบอยู่ในโหนดสาขา และโหนด 2 เป็นโหน ก็น้อยเกินไปเกิดขึ้น น้อยเกินไปเป็น "ถาวร" โดยโอนย้ายค่าจากโหนหลักไปยังโหนที่น้อยเกินไปเกิดขึ้น และการโอนย้ายค่าจากพี่น้องที่มี 3 หรือ 4 โหน ถ้าโหนดซึ่งเกิดขึ้นน้อยเกินไปไม่มีพี่น้องที่มี 3 หรือ 4 โหน แล้วฟิวชั่นเกิดขึ้น ฟิวชั่นที่ต้องโหนน้อยเกินไปเป็น 3-โหนดที่ประกอบด้วยค่าจากโหนพี่น้องและค่าแยกจากแม่ถ้าค่าเป็นลบไม่ได้อยู่ในโหนดสาขา แล้ว ก็ถูกแทนที่ ด้วยรุ่นก่อนทันที และค่าของรุ่นก่อนถูกลบออกจากต้นจัดเก็บข้อมูล2-3-4 แผนภูมิสามารถจัดเก็บในรูปแบบเดียวกับ B-ต้นไม้ แต่สำหรับเงินนั้นไม่ได้ตั้งอยู่บนอุปกรณ์เก็บข้อมูลภายนอก จะเหมาะในการเก็บข้อมูลที่เป็นต้นไม้ค้นหาแบบทวิภาค สิ่งเดียวที่ต้องแตกต่างคือ ว่ามีค่าอยู่ภายใน 2-3-4 โหนดหรือว่าพวกเขาอยู่ในโหน แสดงการเชื่อมโยงระหว่างค่าในโหนให้ มีการเชื่อมโยงสีแดง และแสดงการเชื่อมโยงระหว่างค่าหลัก/รองตามลิงค์สีดำ ดังนั้น:2-โหน: ผลลัพธ์ใน 3-โหน: ผลลัพธ์หรือใน 4-โหน: ผลลัพธ์ใน ต้นไม้แดงดำชนิดของการแสดงผลต้นไม้สีแดงดำ ซึ่งเป็นต้นไม้ค้นหาแบบทวิภาค มีสองชนิดของการเชื่อมโยง/โหน สี ดำ และสีแดงที่ตรงตามคุณสมบัติต่อไปนี้:black condition - every path from the root to a leaf node has the same number of black links/nodesred condition - no path from the root a leaf node has two or more consecutive red links/nodes (ie. every red node will have a black parent)the root is always blackThe nodes in a Red-Black Tree might be represented as follows:template class RedBlackNode{public: ... private: T data; char color; // 'R' if the incoming link is red, 'B' if the incoming link is black RedBlackNode *leftChild, *rightChild;};Processing Red-Black TreesInsertionA value is inserted into the tree using the standard binary search tree algorithm, however a decision must be made as to whether it should be inserted as a red or black link/node. If the node is inserted as a black link/node, then the number of black links/nodes in the one path would increase, which would violate the black condition. Therefore the node will be inserted as a red link/node.This could result in a violation of the red condition but that can be fixed by performing either a color change or a rotation. Three possible cases arise:Case 1: If the parent node is a black node, then insertion is finished.Case 2: If the parent node is a red node and the aunt/uncle node is black.Case 2a: If the node was inserted into the left child of the left child of the grandparent, then the violation is fixed by performing a single right rotation. Case 2b: If the node was inserted into the right child of the right child of the grandparent, then the violation is fixed by performing a single left rotation.
Case 2c: If the node was inserted into the right child of the left child of the grandparent, then the violation is fixed by performing a left-right rotation.
Case 2d: If the node was inserted into the left child of the right child of the grandparent, then the violation is fixed by performing a right-left rotation.
After all of the rotations, the parent node is made black and the child nodes are made red.
Case 3: If the parent node is a red node and the aunt/uncle node is red.
The parent and aunt/uncle nodes will be made black and the grandparent node will be made red. The exception to the grandparent becoming red is if the grandparent is the root of the tree - in this case it will remain black.
OR if 84 is the root, then
Fixing one violation of the red condition could cause it to propagate up the tree. The violations should be fixed until the root of the tree is reached.
การแปล กรุณารอสักครู่..

2-3-4 ต้นไม้รูปแบบใน B-ต้นไม้เป็นต้นไม้ 2-3-4 ซึ่งเป็นต้นไม้ MultiWay ที่ทุกโหนดที่ไม่ได้มีใบที่ 2, 3 หรือ 4 ลูก ดังนั้น: ร้านค้าในแต่ละโหนดที่มากที่สุด 3 ค่าแต่ละโหนดภายใน 2 โหนด 3 โหนดหรือ 4 โหนดใบทั้งหมดที่มีอยู่ในระดับเดียวกันกำลังดำเนินต้นไม้ 2-3-4 ค้นหาเป็นเช่นเดียวกับที่มีการค้นหา MultiWay ต้นไม้. แทรกเข้าไปในต้นไม้ 2-3-4 เริ่มต้นด้วยโหนดเดียวที่ค่าจะถูกแทรกจนกระทั่งมันกลายเป็นเต็มรูปแบบ (เช่น. จนกระทั่งมันกลายเป็น 4 โหนด) ค่าต่อไปที่จะถูกแทรกจะทำให้เกิดการแยกออกเป็นสองโหนดหนึ่งที่มีค่าน้อยกว่าค่ามัธยฐานและค่าอื่น ๆ ที่มีค่ามากกว่าค่าเฉลี่ย ค่าเฉลี่ยจะถูกเก็บไว้ในโหนดแม่ เป็นไปได้ว่าการแทรกอาจก่อให้เกิดการแยกถึงโหนดราก. ใส่ค่า 53, 27, 75, 25, 70, 41, 38, 16, 59, 36, 73, 65, 60, 46, 55, 33, 68, 79, 48 และ25 การใส่ผลในการแยก: ใส่ 38 ทำให้เกิดการแยก: ใส่ 73 ทำให้เกิดการแยก: ใส่ 46 ผลในการแยกที่แพร่กระจายได้ถึงราก: ใส่ 55 ทำให้เกิดการแยก: ลบจาก 2-3 -4 ต้นไม้มักจะเกิดขึ้นในโหนดใบ. หากค่าที่จะลบอยู่ในโหนดใบและโหนดที่ 3 หรือ 4 โหนดแล้วลบง่าย - ค่าจะถูกลบออกและโหนดจะกลายเป็น 2 หรือ 3 โหนดตามลำดับ. ถ้าค่าที่จะลบที่อยู่ในใบโหนดและโหนดที่ 2 โหนดแล้ว underflow เกิดขึ้น underflow คือ "คงที่" โดยการโอนค่าจากโหนดแม่ไปยังโหนดที่เกิดขึ้นอันเดอร์โฟล์และถ่ายโอนค่าจากพี่น้องที่มี 3 หรือ 4 โหนด ถ้าโหนดที่ underflow เกิดขึ้นไม่ได้มีพี่น้องที่เป็น 3 หรือ 4 โหนดแล้วฟิวชั่นที่เกิดขึ้น ฟิวชั่นต้องกลายเป็นอันเดอร์โฟล์โหนด 3 โหนดที่มีค่าจากโหนดพี่น้องและความคุ้มค่าแยกจากแม่. ถ้าค่าที่จะลบไม่ได้อยู่ในโหนดใบแล้วมันจะถูกแทนที่โดยก่อนหน้านี้ได้ทันทีและ ค่าบรรพบุรุษจะถูกลบออกจากต้นไม้. การเก็บรักษาต้นไม้ 2-3-4 สามารถเก็บไว้ในลักษณะเดียวกับ B-ต้นไม้ แต่สำหรับจำนวนเงินขนาดเล็กของข้อมูลที่ไม่ได้ตั้งอยู่บนอุปกรณ์จัดเก็บข้อมูลภายนอกมันจะเหมาะในการจัดเก็บ ข้อมูลที่เป็นต้นไม้ค้นหาแบบทวิภาค สิ่งเดียวที่จะต้องโดดเด่นไม่ว่าจะเป็นค่าที่มีอยู่ภายใน 2-3-4 โหนดหรือว่าพวกเขาจะอยู่ในโหนดลูก ให้การเชื่อมโยงระหว่างค่าภายในโหนดเป็นตัวแทนด้วยการเชื่อมโยงสีแดงและการเชื่อมโยงระหว่างผู้ปกครอง / ค่าเด็กถูกแทนด้วยการเชื่อมโยงสีดำ ดังนั้น: 2 โหนด: ผลใน3 โหนด: ผลลัพธ์ในหรือ4 โหนด: ผลลัพธ์ในสีแดงสีดำต้นไม้ชนิดของผลการเป็นตัวแทนในต้นไม้สีแดงสีดำซึ่งเป็นต้นไม้ค้นหาแบบทวิภาคที่มีสองประเภท การเชื่อมโยง / โหนด, สีแดงและสีดำที่ตอบสนองคุณสมบัติต่อไปนี้: สภาพสีดำ - ทุกเส้นทางจากรากไปยังโหนดใบมีหมายเลขเดียวกันของการเชื่อมโยงสีดำ / โหนดสภาพสีแดง - เส้นทางจากโหนดรากใบมีสองคนหรือมากกว่า การเชื่อมโยงติดต่อกันสีแดง / โหนด (เช่นทุกโหนดจะมีสีแดงสีดำผู้ปกครอง.) รากอยู่เสมอสีดำโหนดในต้นไม้สีแดงสีดำอาจจะแสดงดังต่อไปนี้แม่แบบ
ระดับ RedBlackNode
{
ส่วนกลาง:
... ส่วนตัว: ข้อมูล T; สีถ่าน; // 'R' ถ้าเชื่อมโยงเข้ามาเป็นสีแดง 'B' ถ้าเชื่อมโยงเข้ามาเป็นสีดำRedBlackNode leftChild * * rightChild; }; ประมวลผลต้นไม้สีแดงสีดำแทรกค่าถูกแทรกเข้าไปในต้นไม้โดยใช้การค้นหาแบบไบนารีมาตรฐานขั้นตอนวิธีต้นไม้ แต่การตัดสินใจจะต้องทำเป็นไปได้ว่ามันควรจะใส่เป็นลิงค์สีแดงหรือสีดำ / โหนด ถ้าโหนดถูกแทรกเป็นสีดำเชื่อมโยง / โหนดแล้วจำนวนของการเชื่อมโยงสีดำ / โหนดในเส้นทางหนึ่งจะเพิ่มขึ้นซึ่งจะเป็นการละเมิดเงื่อนไขสีดำ ดังนั้นโหนดจะถูกแทรกเป็นลิงค์สีแดง / โหนด. ซึ่งอาจส่งผลในการละเมิดสภาพสีแดง แต่ที่สามารถแก้ไขได้โดยการดำเนินการอย่างใดอย่างหนึ่งการเปลี่ยนสีหรือการหมุน กรณีที่สามเป็นไปได้ที่จะเกิดขึ้น: กรณีที่ 1: ถ้าโหนดแม่เป็นโหนดสีดำแล้วแทรกเสร็จสิ้น. กรณีที่ 2: ถ้าโหนดแม่เป็นโหนดสีแดงและป้า / ลุงโหนดเป็นสีดำ. กรณี 2a: ถ้าโหนดถูกแทรก เข้าไปในเด็กทางด้านซ้ายของเด็กด้านซ้ายของปู่ย่าตายายแล้วละเมิดได้รับการแก้ไขโดยการดำเนินการที่เหมาะสมในการหมุนเดียว. กรณี 2b: ถ้าโหนดที่ถูกใส่เข้าไปในเด็กขวาของเด็กด้านขวาของปู่ย่าตายายแล้วละเมิดจะถูกแก้ไขโดย . การแสดงการหมุนซ้ายเดียวกรณี 2c: ถ้าโหนดที่ถูกใส่เข้าไปในเด็กขวาของเด็กด้านซ้ายของปู่ย่าตายายแล้วละเมิดได้รับการแก้ไขโดยการดำเนินการหมุนซ้ายขวา. กรณี 2d: ถ้าโหนดที่ถูกใส่เข้าไปในซ้าย . ลูกของเด็กด้านขวาของปู่ย่าตายายแล้วละเมิดได้รับการแก้ไขโดยการดำเนินการหมุนซ้ายขวาหลังจากที่ทุกผลัดโหนดแม่ทำสีดำและโหนดลูกที่ทำสีแดง. กรณีที่ 3: ถ้าโหนดแม่เป็น สีแดงและโหนดโหนดป้า / ลุงเป็นสีแดง. พ่อแม่และป้า / โหนดลุงจะทำสีดำและโหนดปู่ย่าตายายจะทำสีแดง ยกเว้นปู่ย่าตายายกลายเป็นสีแดงคือถ้าปู่ย่าตายายเป็นรากของต้นไม้ - ในกรณีนี้มันจะยังคงสีดำ. หรือ 84 ถ้าเป็นรากแล้วแก้ไขหนึ่งละเมิดเงื่อนไขแดงอาจทำให้เกิดการแพร่กระจายขึ้นไปบนต้นไม้ ละเมิดควรได้รับการแก้ไขจนรากของต้นไม้ที่จะมาถึง
การแปล กรุณารอสักครู่..

ในรูปแบบต้นไม้บนต้นไม้เป็น 2-3-4 Tree ซึ่งเป็น multiway ต้นไม้ซึ่งทุกใบ ( ไม่ได้ 2 , 3 หรือ 4 คน โดย :
แต่ละโหนดเก็บมากที่สุด 3 ค่า
แต่ละโหนดภายในเป็น 2-node 3-node , หรือนี้
ใบทั้งหมดอยู่ในระดับเดียวกัน
หากระบวนการผลิตต้นไม้ก็เหมือนกับ multiway ต้นไม้ค้นหา
แทรกเข้าไปในต้นไม้ เริ่มต้นด้วยโหนดเดียวที่ค่าแทรกจนกลายเป็นเต็มรูปแบบ ( เช่น จนกว่ามันจะกลายเป็นเกอร์ ) ค่าถัดไปที่ถูกแทรกจะทำให้แยกเป็นสองจุดหนึ่งที่มีค่าต่ำกว่าค่าเฉลี่ยและส่วนอื่น ๆที่มีค่าสูงกว่าค่ามัธยฐาน ค่า median แล้วเก็บไว้ในผู้ปกครองโหนดมันเป็นไปได้ที่อาจก่อให้เกิดการแยกแทรกถึงปมราก
ใส่มูลค่า 53 , 27 , 75 , 25 , 70 , 41 , 38 , 16 , 59 , 36 , 73 , 65 , 60 , 46 , 55 , 33 , 68 , 79 และ 48
ใส่ 25 ผลลัพธ์ใน โดย :
ใส่ 38 สาเหตุแยก :
การแทรก 73 สาเหตุแยก :
ใส่ 46 ผลลัพธ์ในแยกที่แพร่กระจายได้ถึงราก :
ใส่ 55 สาเหตุแยก :
ลบจากในต้นไม้มักจะเกิดขึ้นในปมใบ
ถ้าค่าเป็นลบอยู่ในโหนดที่โหนดใบ และเป็น 3 หรือนี้ งั้นลบง่าย - มีค่าเป็นลบและโหนดจะกลายเป็น 2 หรือ 3 โหนดตามลำดับ .
ถ้าค่าเป็นลบ อยู่ในโหนดที่โหนดใบ และมี 2 ต่อม แล้วขีดเส้นใต้เกิดขึ้นขีดเส้นใต้ " ถาวร " โดยการโอนค่าจากโหนดกับโหนดหลักที่ขีดเส้นใต้เกิดขึ้นและโอนค่าจากพี่น้องที่เป็น 3 หรือนี้ . ถ้าโหนดที่ขีดเส้นใต้เกิดขึ้นไม่มีพี่น้องที่เป็น 3 หรือนี้ งั้นฟิวชั่นเกิดขึ้นฟิวชั่นที่ต้องขีดเส้นใต้โหนดเป็น 3-node ที่มีค่าจากพี่น้องโหนดและแยกค่าจากผู้ปกครอง
ถ้าค่าที่ต้องการลบไม่ได้อยู่ในปมใบก็ถูกแทนที่โดยบรรพบุรุษของมันทันที และมูลค่าเป็นบรรพบุรุษที่ถูกลบจากต้นไม้
กระเป๋า
ในต้นไม้ สามารถเก็บไว้ในลักษณะเดียวกับต้นไม้ ,แต่สำหรับจำนวนเงินขนาดเล็กของข้อมูลที่ไม่ได้อยู่ในอุปกรณ์จัดเก็บข้อมูลภายนอกมันจะเหมาะที่จะเก็บข้อมูลเช่นต้นไม้ค้นหาแบบไบนารี สิ่งเดียวที่ต้องเน้นว่าคุณค่าภายในที่มีอยู่ในโหนดหรือไม่ว่าพวกเขาอยู่ในโหนดลูกทำให้การเชื่อมโยงระหว่างค่าภายในโหนดจะแสดงด้วยสีแดง การเชื่อมโยงและการเชื่อมโยงระหว่างค่าแม่ / เด็กจะแสดงโดยการเชื่อมโยงสีดำ โดย :
2-node ในผล
3-node : ผลหรือนี้
:
ผล
สีแดงดำต้นไม้
นี้ประเภทของการแสดงผลในสีแดงดำต้นไม้ซึ่งเป็นต้นไม้ค้นหาแบบทวิภาคที่มีสองประเภทของการเชื่อมโยง / จุดแดง สีดำ ,ที่ตรงกับคุณสมบัติต่อไปนี้ :
สีดำสภาพ - ทุกเส้นทางจากรากถึงใบโหนดมีหมายเลขเดียวกันของการเชื่อมโยงโหนดดำ / แดงสภาพ -
เส้นทางจากโหนดราก ใบมีสองหรือมากกว่าติดต่อกันเชื่อมโยงโหนด เช่น แดง แดงทุกโหนดจะมีผู้ปกครองสีดำ )
ราก เป็นสีดำ
โหนดในต้นไม้สีดำแดง อาจจะแสดงได้ดังนี้
>
< คลาส T แม่แบบชั้น redblacknode
{
สาธารณะ :
. . . . . . .
ส่วนตัว :
t ข้อมูล ;
ถ่านสี ; / / ' R ' ถ้าเข้าลิงค์แดง ' B ' ถ้าการเชื่อมโยงขาเข้าสีดำ
redblacknode * leftchild * rightchild ;
} ;
การประมวลผลสีแดงดำต้นไม้
.
ค่าจะถูกแทรกในต้นไม้โดยใช้มาตรฐานการค้นหาแบบทวิภาคขั้นตอนวิธีต้นไม้ แต่ต้องตัดสินใจว่าควรแทรกเป็นสีแดงหรือสีดำที่ลิงค์ / โหนดถ้าโหนดถูกแทรกเป็นลิงค์ / ดำโหนดแล้วจํานวนสีดำเชื่อมโยงโหนดในหนึ่งเส้นทางจะเพิ่มขึ้นซึ่งจะละเมิดเงื่อนไขสีดำ ดังนั้นปมจะถูกแทรกเป็นสีแดงเชื่อมโยงโหนด /
นี้อาจจะมีผลในการละเมิดเงื่อนไขแดงแต่สามารถแก้ไขได้โดยการให้เปลี่ยนสี หรือหมุน สามกรณีที่เป็นไปได้เกิดขึ้น :
กรณีที่ 1 :ถ้าพ่อแม่โหนดเป็นโหนดสีดำแล้วใส่เสร็จแล้ว
กรณีที่ 2 ถ้าพ่อแม่โหนดเป็นโหนดแดงและป้า / ลุงโหนดดำ .
2a
กรณี : ถ้าโหนดถูกแทรกลงในเด็กที่ด้านซ้ายของลูกด้านซ้ายของปู่ ย่า ตา ยาย แล้วแก้ไขโดยการละเมิด แสดงการหมุนทางขวาเดียว
เคส 2B : ถ้าโหนดถูกแทรกลงในเด็กสิทธิเด็กด้านขวา ของปู่ ย่า ตา ยาย ,แล้วการละเมิดคงที่โดยการหมุนซ้ายเดียว
กรณี 2C : ถ้าโหนดถูกแทรกลงในเด็กสิทธิเด็กด้านซ้ายของปู่ ย่า ตา ยาย แล้ว การละเมิดการแก้ไขโดยการแสดงการหมุนซ้ายขวา
กรณี 2D : ถ้าโหนดถูกแทรกลงในลูกซ้าย เด็กถูกของปู่ ย่า ตา ยาย แล้ว การละเมิดการแก้ไขโดยการ หมุน ซ้าย ขวา .
หลังจากทั้งหมดของการหมุน แม่ดำและลูกโหนดเป็นโหนดที่ทำสีแดง
กรณีที่ 3 ถ้าพ่อแม่โหนดเป็นโหนดแดงและป้า / ลุงโหนดแดง
แม่และป้า / ลุงโหนดจะทำสีดำปู่ย่าตายายโหนดและจะทำสีแดง ยกเว้นจะเป็นสีแดง ถ้าปู่ย่าปู่ย่าตายายเป็นรากของต้นไม้ -- ในกรณีนี้จะยังคงดำ
หรือหากมีรากแล้ว
แก้ไขหนึ่งฝ่าฝืนเงื่อนไขแดงอาจทำให้มันขยายขึ้น ต้นไม้ การละเมิดควรจะคงที่จนถึงรากของต้นไม้
ถึง
การแปล กรุณารอสักครู่..
