Langsung ke konten utama

Binary Tree Introduction


BINARY TREE DATA STRUCTURE
              A tree whose elements have at most 2 children is called a binary tree. Since each element in a binary tree can have only 2 children, we typically name them the left and right child.
PARTS OF NODE IN BINARY TREE :
1.      Data,
2.      Pointer to left child, and
3.      Pointer to right child.
THE USED FROM BINARY TREE ARE FOLLOWING :
1.      Manipulate hierarchical data,
2.      Make information easy to search,
3.      Manipulate sort list of data,
4.      Composting digital images for visual effect,
5.      Router Algorithms, and
6.       Form of a multi-stage decision-making (see business chess).
TREE’S PART
1.      Root : The topmost node of the tree. The root always placed on very top of tree.
2.      Children : The element directly under a root. Like the above there said, the tree HAVE the most 2 children. As long they have 2 children, they can be called TREE.
There are a common properties in tree we’ve should known about it. The common properties is the maximum number of nodes at level ‘l’ where ‘l’ is a root of binary tree is . For example, lets take a number for ‘l’ is 1 and we input the 1 into the formula, we can get 2 of the maximum nodes. And the other child below the nodes can be calculate by 2*.
The next common property is maximum number of nodes in a binary tree of height ‘h’ is  . This is a simple geometric series with h terms and sum of this series is 2h – 1. In some books, height of the root is considered as 0. In this convention, the above formula becomes 2h+1 – 1.

TYPE OF BINARY TREE
1.      Full Binary Tree 
A Binary Tree is full if every node has 0 or 2 children. Following are examples of a full binary tree. We can also say a full binary tree is a binary tree in which all nodes except leaves have two children.
2.     Complete Binary Tree
A Binary Tree is complete Binary Tree if all levels are completely filled except possibly the last level and the last level has all keys as left as possible
3.     Perfect Binary Tree 
A Binary tree is Perfect Binary Tree in which all internal nodes have two children and all leaves are at the same level.
4.     Balanced Binary Tree
A binary tree is balanced if the height of the tree is O(Log n) where n is the number of nodes. For Example, AVL tree maintains O(Log n) height by making sure that the difference between heights of left and right subtrees is at most 1. Red-Black trees maintain O(Log n) height by making sure that the number of Black nodes on every root to leaf paths are same and there are no adjacent red nodes. Balanced Binary Search trees are performance wise good as they provide O(log n) time for search, insert and delete.
5.     A degenerate (or pathological) tree
 A Tree where every internal node has one child. Such trees are performance-wise same as linked list.
           
            For further information about Binary Tree, there are following source that I take for this document.
            Sources :


Komentar

Postingan populer dari blog ini

Heap & Tries {Theory}

HEAP & TRIES 1.        Heap Dalam  ilmu komputer , sebuah  heap  adalah struktur data yang berdasarkan konsep struktur data  pohon . Di heap, juga diterapkan konsep binary tree. Terdapat 3 jenis heap, diantaranya : a.      Min heap Min heap merupakan heap yang node rootnya adalah angka terkecil dan setiap anak dari rootnya selalu lebih kecil daripada parentnya. Biasanya min heap ini, dia ascending ( dari terkecil ke terbesar ). b.     Max heap Max heap ini sama seperti min heap, tapi bedanya adalah angka yang berada di root adalah angka terbesar dan max heap ini descending ( dari terbesar ke terkecil ). c.      Min Max heap Untuk min max heap ini cukup unik, dimana root dari heap ini merupakan angka terkecil didalam tree nya, tapi angka yang berada dii node anak dari sebuah root merupakan angka paling besar dan berlaku seterusnya sampai ke bawah. Berikut ad...

AVL Tree [Theory]

AVL TREE AVL tree is a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees cannot be more than one for all nodes. For example :    (Left : Correct AVL Tree || Right : Wrong AVL Tree) The reason why right AVL tree is wrong because the above tree is not AVL because differences between heights of left and right subtrees for 8 and 18 is greater than 1. AVL trees have an additional guarantee: The difference between the depth of right and left subtrees cannot be more than one. In order to maintain this guarantee, an implementation of an AVL will include an algorithm to rebalance the tree when adding an additional element would upset this guarantee. AVL trees have a worst case lookup, insert and delete time of O(log n). In AVL Tree, we can perform Insertion and Deletion. ·        Insertion To make sure that the given tree remains AV...