Tree
Tree
A tree is a non-linear data structure with hierarchical relationship between its element without
having any cycle.
Properties of Tree
Tree Terminology
A binary tree is a tree data structure in which each node has at most two children often referred as
the left and right children.
Binary tree is a family data structure (Binary Search Tree, Heap tree, Red Black Tree, Syntax Tree, etc.)
• Binary trees are prerequisite for more advanced tree data structure
• Huffman coding problem, heap priority problem and expression parsing problem can be
solved efficiently using binary tree
• Full Binary Tree: It has zero or two children but not one
• Perfect Binary Tree: All non-leaf node has two children and they are on the same level
• Complete Binary Tree: All levels are completely filled except the last level. However, has keys
as left as possible
• Balanced Binary Tree: Each leaf is not more a certain distance from the root node from any
other. This means the leaf nodes of the tree are all on the same level
Binary Search Tree
• In the left subtree the value of the node is less than or equals to the parent node value
• In the right subtree the value of the node is greater than the its parent node’s value
• It performs faster than binary tree when inserting and deleting node
• PreOrder Tranversal
• InOrder Traversal
• PostOrder Traversal
• LevelOrder Traversal