Presentation is loading. Please wait.

Presentation is loading. Please wait.

Binary Tree Representation Of 2-3-4 Trees Problems with 2-3-4 trees. 2- and 3-nodes waste space. Overhead of moving pairs and pointers when changing among.

Similar presentations


Presentation on theme: "Binary Tree Representation Of 2-3-4 Trees Problems with 2-3-4 trees. 2- and 3-nodes waste space. Overhead of moving pairs and pointers when changing among."— Presentation transcript:

1 Binary Tree Representation Of 2-3-4 Trees Problems with 2-3-4 trees. 2- and 3-nodes waste space. Overhead of moving pairs and pointers when changing among 2-, 3-, and 4-node use. Represented as a binary tree for improved space and time performance. 2-3-4 node structure LCP1LMCP2RCRMCP3

2 Representation Of 4-node xyz abc d a bcd z y x

3 Representation Of 3-node xy ab c a bc y x a b y x c or

4 Representation Of 2-node a x b x a b

5 Example 10 7 8 1 5 30 40 20 25 35 45 60 3

6 Properties Of Binary Tree Representation Nodes and edges are colored.  The root is black.  Nonroot black node has a black edge from its parent.  Red node has a red edge from its parent. Can deduce edge color from node color and vice versa. Need to keep either edge or node colors, not both.

7 Red Black Trees Colored Nodes Definition Binary search tree. Each node is colored red or black. Root and all external nodes are black. No root-to-external-node path has two consecutive red nodes. All root-to-external-node paths have the same number of black nodes

8 Red Black Trees Colored Edges Definition Binary search tree. Child pointers are colored red or black. Pointer to an external node is black. No root to external node path has two consecutive red pointers. Every root to external node path has the same number of black pointers.

9 2-3-4 & Red-Black Equivalence 10 7 8 1 5 30 40 20 25 35 45 60 3

10 Red Black Tree The height of a red black tree that has n (internal) nodes is between log 2 (n+1) and 2log 2 (n+1). C++ STL implementation java.util.TreeMap => red black tree

11 Top-Down Insert Mimic 2-3-4 top-down algorithm. Split 4-nodes on the way down.

12 Root Is A 4-node xyz abc d x y z a bcd a bcd z y x a bcd z y x

13 4-node Left Child Of 2-node wxy abc d z ew z y a bcd x e z w y x abcd e z w y x abcd e

14 4-node Left Child Of 3-node vwx abc d f zy e v x a b cd wyz fe y v x w abcd z ef y v x w abcd z ef

15 vwx abc d f zy e v x a b cd wyz fe y v x w ab z e f c d y v x w abcd z ef

16 4-node Middle Child Of 3-node v w y x bc z a f d e x w v y a dbc z e f wxy bcd e f zv a wa bc f y de vxz

17 d z w y x bc v a f e x w v y a dbc z e f wxy bcd e f zv a wa bc f y de vxz

18 4-node Right Child Of 3-node One orientation of 3-node requires color flip. Other orientation requires RR rotation.

19 Top-Down Delete Mimic 2-3-4 top-down delete. Color flip followed by possible rotation.

20 Red-Black Analysis Less memory required than by 2-3-4 representation. Less time required by 4-node splits when red-black representation is used. O(log n) rotations per insert/delete.


Download ppt "Binary Tree Representation Of 2-3-4 Trees Problems with 2-3-4 trees. 2- and 3-nodes waste space. Overhead of moving pairs and pointers when changing among."

Similar presentations


Ads by Google