Selasa, 27 Maret 2018

Tree & Binary Tree

Tree & Binary Tree

1. Binary Tree
    A binary tree is a tree data structure in which each node has at most two children, which 
    are referred to as the left child and the right child.

Types of Binary Tree

Perfect binary tree is a binary tree in which every level are at the same depth.
Complete binary tree is a binary tree in which every level, except possibly the last, is completely
  filled, and all nodes are as far left as possible. A perfect binary tree is a complete binary tree.
Skewed binary tree is a binary tree in which each node has at most one child.
Balanced binary tree is a binary tree in which no leaf is much farther away from the root than any
  other leaf (different balancing scheme allows different definitions of “much farther”).

Perfect Binary Tree









Complete Binary Tree










Skewed Binary Tree














2. Difference Between Tree & Graph

       Tree :

       1. A tree is a special kind of graph that there are never multiple paths exist. There is always one         way to get from A to B.
       2. Tree must be connected. 
   3. Since it connected we can reach from one particular node to all other nodes. This                 kind of searching is called traversal.
   4. Tree contains no loops, no circuits. 
5. There must be a root node in tree.

Graph :

1. A graph is a system that has multiple ways to get from any point A to any
    other point  B.
2. Graph may not be connected.
3. Traversal always not applicable on graphs. Because graphs may not be connected.
4. Graph may contain self-loops, loops.
5. There is no such kind of root node in graphs.

Tidak ada komentar:

Posting Komentar