Tree

What is Tree?


A tree is a data structure, each node points to a number of nodes. A tree is an example of non-linear data structures. A tree structure is a way of representing the hierarchical nature of a structure in a graphical form.




  • The root of a tree is the node with no parents.
  • A node with no children is called a leaf node.
  • Children of the same parent are called siblings.
  • A node "p" is an ancestor of node "q" if there exists a path from "root" to "q" and "p" appears on the path. The node "q" is called descendant of p.
  • Set of all node at a given depth is called the level of the tree. The root node is at level zero.
  • The height of the tree is the maximum height among all the nodes in the tree and depth of the tree is the maximum depth among all the nodes in the tree.

Binary Tree

A tree is called a binary tree if each node has zero child, one child or two children.

Types of binary tree

  • Strict Binary Tree: If each node has exactly two children or no children.
  • Full Binary Tree: If each node has exactly two children and all the leaf node are at the same level.
  • Complete Binary Tree: If all leaf nodes are at height "h" or "h-1" and also without missing any number in the sequence.

Application of Binary Tree

  • Expression trees are used in compilers.
  • Huffman coding trees that are used in the data compression algorithm.
  • Binary Search Tree (BST), which supports search, insertion, and deletion on the collection of items in O(logn).
  • Priority Queues (PQ), which support search and deletion of minimum or maximum on the collection of items in logarithmic time (in worst case).
  • One reason to use trees might be because you want to store information that naturally forms a hierarchy. For example, the file system on a computer.
  • Manipulate hierarchical data.
  • Make information easy to search.
  • Manipulate sorted lists of data.
  • As a workflow for compositing digital images for visual effects.
  • Router algorithms.
  • Form of a multi-stage decision-making.




Comments

Popular posts from this blog

AVL (Adelson-Velskii and Landis) Trees

How to Build REST API Using PHP