tree_ds_types_of_Tree_DS

# There are about 80+ different types of Tree Data Structure 🥴 # but we'll talk about four Tree DS now:

  1. Tree (general kind)( that Data Structure which has root, child node(branchs, leaves) )
  2. Binary Tree (That special kind of Tree that can have only Two Child Nodes)
  3. Binary Search Tree.
  4. Heap.


# ========= Binary Tree =========

# A Binary Tree could have imum of two childern. Hence, in a binary Tree, any given node could have zero, one or two nodes but not more than two 🤐. # They cannot have more than two Nodes or Children



           A
         /   \
        D     C
       / \   / \
      E   F I   L
      


# ========= Binary Search Tree (BST) ============

# 'Binary Search Tree (BST) is a special kind of Binary Tree (BST), it follows Two Rules:

  1. The value of the Left Child Node will be smaller than the value of Parent Node
  2. and the value of the Right Child Node will be greater or higher the value of Parent Node.


           5
         /   \
        2     8
       / \   / \
      1   4 6  11
              /  \
             9   14
             


# ============= Heap ============

# Basically, A 'Heap' is also a special kind of 'Binary Tree'.


# When the value of any Parent Node is higher or equal to any Child Node, the Tree is called 'Max Heap' 😎

Max Heap

           12
         /   \
        10    8
       / \   / 
      5   6 2

# and when the value of any Parent Node is lower or equal to any Child Node, the Tree is called 'Min Heap' 😎

Max Heap


 		   2
         /   \
        3     5
       / \   / 
      4   6 8



BST: the left is smaller and the right is bigger


Post a Comment

0 Comments