Saturday, October 24, 2015

2-3 Trees and 2-3-4 Trees

2-3 Trees 


A 2-3 Tree is a data(tree) structure where every bode with children has either two children and two data elements 

2-3 Tree Structure

Properties 

  1. Every internal node is a 2-node or a 3-node 
  2. All leaves are at the same level 
  3. All data is kept in sorted order.
Operations

1. Search 
               Similar to BST, since the data elements in each node is ordered 
2. Insertion
              Works by searching for the proper location of the key and adds it there. If the node becomes a 4-node, then the split from the 2-nodes and the middle key is moved up to the parent.
3. Deletion 
            Reverse of insertion


2-3-4 trees 

2-3-4 trees are self balancing data structure. The time complexity for the trees involve O(log(n))

Properties: 
  • Every node is a 2-, 3- or a 4- node and hold 1,2,or 3 data elements respectuvely 
  • All leaves are kept at same depth 
  • All data is kept in sorted order.
Operations and working functions are similar to 2-3 Trees as explained above.


Blogs to refer: 1,2