0% found this document useful (0 votes)
15 views

Tree

Uploaded by

khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Tree

Uploaded by

khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

What is a Tree?

A tree is a non-linear data structure with hierarchical relationship between its element without
having any cycle.

Properties of Tree

• Represent hierarchical data


• Each node has two sub-components
• Base category and sub-categories under it

Why do we need Tree?

• Quicker and easier to access the data


• Store hierarchical data like folder structure, organization structure, HTML/XML data
• There are many different types of tree data structure which perform better in various
situation.
o Binary Search Trees

Tree Terminology

• Root: top node without parent


• Edge: a link between parent and child
• Leaf: a node which does not have children
• Sibling: children of same parent
• Ancestor: parent, grandparent, great grandparent of a node
• Depth of node: a length of path from root to node
• Height of node: a length of path from the node tp the deepest node
• Depth of tree: depth of root node
• Height of tree: height of root node

What is Binary Tree

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.)

Why Binary Tree?

• 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

Types of 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

Why Binary Search Tree

• It performs faster than binary tree when inserting and deleting node

Binary Search Tree Traversal

• PreOrder Tranversal

• InOrder Traversal
• PostOrder Traversal

• LevelOrder Traversal

You might also like