Trees�
By
Mr. Abhijit T. Somnathe
What is Tree?
What is Tree?
What is Tree?
What is Tree?
Tree
Tree Terminology
Tree Terminology
Tree Terminology
Tree Terminology
Properties of Tree Data Structure
Properties of Tree Data Structure
Properties of Tree Data Structure
Properties of Tree Data Structure
Types of Tree
1. General Tree
2. Binary Tree
3. Binary Search Tree
4. AVL Tree
5. Red-Black Tree
6. N-ary Tree
General Tree
Binary Tree
Binary Tree
Binary Search Tree
Binary Search Tree
AVL Tree
AVL Tree
AVL Tree
Red-Black Tree
Red-Black Tree
Red-Black Tree
N-ary Tree
N-ary Tree
Binary Tree Representation
Binary Tree Representation
Array Representation of Binary Tree
Array Representation of Binary Tree
Linked List Representation of Binary Tree
Linked List Representation of Binary Tree
Linked List Representation of Binary Tree
Binary Tree Traversals
Binary Tree Traversals
Binary Tree Traversals
In - Order Traversal (Left Child - Root – Right Child)
In - Order Traversal (Left Child - Root – Right Child)
Pre - Order Traversal (Root - Left Child – Right Child)
Pre - Order Traversal (Root - Left Child – Right Child)
Post - Order Traversal (Left Child - Right Child - Root)
Post - Order Traversal (Left Child - Right Child - Root)
Basic operations on a Binary Search Tree
Basic operations on a Binary Search Tree
Predecessor of a node
Successor of a node
Basic operations on a Binary Search Tree
Create
Basic operations on a Binary Search Tree
Search
Basic operations on a Binary Search Tree
Basic operations on a Binary Search Tree
Insert
Basic operations on a Binary Search Tree
Deletion
1. No subtree (no children): This one is the easiest one. You can simply just delete the node, without any additional actions required.
2. One subtree (one child): You have to make sure that after the node is deleted, its child is then connected to the deleted node's parent.
3. Two subtrees (two children): You have to find and replace the node you want to delete with its in-order successor (the leftmost node in the right subtree).
Expression Tree
Expression Tree
Construction of an Expression Tree
1. Each leaf is an operand. Examples: a, b, c, 6, 100
2. The root and internal nodes are operators. Examples: +, -, *, /, ^
3. Subtrees are subexpressions with the root being an operator.
Construction of an Expression Tree
1. Read one symbol at a time from the postfix expression.
2. Check if the symbol is an operand or operator.
Construction of an Expression Tree
3. If the symbol is an operand, create a one node tree and push a pointer onto a stack.
4. If the symbol is an operator, pop two pointers from the stack namely T1 & T2 and form a new tree with root as the operator, T1 & T2 as a left and right child.
5. A pointer to this new tree is pushed onto the stack.
Construction of an Expression Tree
Construction of an Expression Tree
Postfix Expression Construction
Construction of an Expression Tree
Construction of an Expression Tree
Construction of an Expression Tree
Huffman Tree
Huffman Tree
Huffman Tree
Huffman Tree
Letter Frequency Table
Huffman Tree
Huffman Tree
Huffman Code
ANY DOUBTS?