SlideShare a Scribd company logo
10
Most read
12
Most read
17
Most read
Binary trees: introduction (complete and
extended binary trees),
Memory representation (sequential, linked)
Binary tree traversal: pre-order, in-order and
post-order (traversal algorithms using stacks)
A tree is a finite set of zero or more nodes
such that:
There is a specially designated node called
the root.
The remaining nodes are partitioned into
n>=0 disjoint sets T1, ..., Tn, where each of
these sets is a tree.
We call T1, ..., Tn the subtrees of the root.
Level and Depth
K L
E F
B
G
C
M
H I J
D
A
Level
0
1
2
3
node (13)
degree of a node(shown by green
number)
leaf (terminal)
nonterminal
parent
children
sibling
ancestor
descendant
level of a node
height(depth) of a tree (4)
3
2 1 3
2 0 0 1 0 0
0 0 0
Terminology
The degree of a node is the number of subtrees
of the node
The degree of A is 3; the degree of C is 1.
The node with degree 0 is a leaf or terminal
node.
A node that has subtrees is the parent of the
roots of the subtrees.
The roots of these subtrees are the children of
the node.
Children of the same parent are siblings.
The ancestors of a node are all the nodes
along the path from the root to the node.
Tree Properties
A
B C
D
G
E F
IH
Property Value
Number of nodes
Height
Root Node
Leaves
Interior nodes
Number of levels
Ancestors of H
Descendants of B
Siblings of E
degree of node A
Binary Trees
A special class of trees: max degree for each
node is 2
Recursive definition: A binary tree is a finite
set of nodes that is either empty or consists of
a root and two disjoint binary trees called the
left subtree and the right subtree.
J
IM
H
L
A
B
C
D
E
F GK
Samples of Trees
A
B
A
B
A
B C
GE
I
D
H
F
Complete Binary Tree
Skewed Binary Tree
E
C
D
Maximum Number of Nodes in BT
The maximum number of nodes on level i of a
binary tree is 2i
, i>=0.
The maximum number of nodes in a binary
tree
of depth k is 2k
-1, k>=1.
Full BT vs. Complete BT
A full binary tree of depth k is a binary tree of depth k
having 2k
-1 nodes, k>=1.
A binary tree with n nodes and depth k is
complete iff its nodes correspond to the nodes numbered
from 1 to n in the full binary tree of depth k.
A
B C
GE
I
D
H
F
A
B C
GE
K
D
J
F
IH ONML
Full binary tree of depth 4Complete binary tree
Complete Binary Tree
If a complete binary tree with n nodes
(depth= log└ n + 1 )┘
is represented sequentially,
then for any node with index i, 1<=i<=n, we have:
parent(i) is at i└ /2┘ if i!=1. If i=1, i is at the root and
has no parent.
leftChild(i) is at 2i if 2i<=n. If 2i>n, then i has no
left child.
rightChild(i) is at 2i+1 if 2i+1<=n. If 2i+1>n,
then i has no right child.
Extended Binary TreeA binary tree T is said to be a 2-tree or an extended binary tree if each
node N has either 0 or 2 children.
The nodes with 2 children are called internal nodes.
The nodes with o children are called external nodes. A
B C
G
D F
A
B C
G
D F
Fig: Binary Tree T Fig: Extended 2-tree
Sequential
RepresentationA
B
--
C
--
--
--
D
--
.
E
[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]
.
[16]
[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]
A
B
C
D
E
F
G
H
I
A
B
E
C
D
A
B C
GE
I
D
H
F
(1) waste space
(2) insertion/deletion
problem
Linked Representation
struct btnode {
int data;
btnode *left, *right;
};
dataleft right
data
left right
Binary Tree Traversals
There are three standard ways of traversing a
binary tree T with root R.
These three algorithms, called:
preorder
inorder
postorder
Arithmetic Expression Using BT
+
*
A
*
/
E
D
C
B
preorder traversal
+ * * / A B C D E
prefix expression
inorder traversal
A / B * C * D + E
infix expression
postorder traversal
A B / C * D * E +
postfix expression
Preorder Traversal (recursive
version)
Algorithm:
1. Process the root R.
2. Traverse the left subtree of R in preorder.
3. Traverse the right subtree of R in preorder.
Pseudo-Code:
void preorder(btnode ptr)
/* preorder tree traversal */
{
if (ptr!=NULL) {
cout<<ptr->data;
preorder(ptr->left);
predorder(ptr->right);
}
}
+ * * / A B C D E
Inorder Traversal (recursive version)
Algorithm:
1. Traverse the left subtree of R in inorder.
2. Process the root R.
3. Traverse the right subtree of R in inorder.
Pseudo-Code:
void inorder(btnode ptr)
/* inorder tree traversal */
{
if (ptr!=NULL) {
inorder(ptr->left);
cout<<ptr->data;
indorder(ptr->right);
}
}
A / B * C * D + E
Postorder Traversal (recursive version)
Algorithm:
1. Traverse the left subtree of R in postorder.
2. Traverse the right subtree of R in postorder.
3. Process the root R.
Pseudo-Code:
void postorder(btnode ptr)
/* postorder tree traversal */
{
if (ptr!=NULL) {
postorder(ptr->left);
postorder(ptr->right);
cout<<ptr->data;
}
}
A B / C * D * E +
Preorder Traversal (using stack)
PREORD(INFO, LEFT, RIGHT, ROOT)
1. Set TOP:= 1, STACK[1]:= NULL and PTR := ROOT.
2. Repeat Steps 3 to 5 while PTR != NULL:
3. Apply PROCESS to INFO[PTR].
4. If RIGHT[PTR]!= NULL then
Set TOP := TOP+1, and STACK[TOP]:= RIGHT[PTR].
5. If LEFT[PTR]!= NULL then
Set PTR:= LEFT[PTR].
Else
Set PTR:= STACK[TOP] TOP:= TOP-1.
[End of If structure]
[End of step 2 Loop]
6. Exit.
+ * * / A B C D E
Inorder Traversal (using stack)
INORD(INFO, LEFT, RIGHT, ROOT)
1.Set TOP:= 1, STACK[1]:= NULL and PTR := ROOT.
2.Repeat while PTR != NULL:
a) Set TOP:=TOP+1, STACK[TOP]:=PTR.
b) Set PTR:= LEFT[PTR].
[End of loop]
3.Set PTR:=STACK[TOP], TOP:=TOP-1.
4.Repeat Steps 5 to 7 while PTR != NULL:
5.Apply PROCESS to INFO[PTR].
6.If RIGHT[PTR]!= NULL, then:
a) Set PTR:=RIGHT[PTR]
b) Go to Step 2.
[End of If structure]
7.Set PTR:=STACK[TOP] and TOP:=TOP-1.
[End of step 4 Loop.]
8.Exit
A / B * C * D + E
Postorder Traversal (using stack)
POSTORD(INFO, LEFT, RIGHT, ROOT)
1.Set TOP:= 1, STACK[1]:= NULL and PTR := ROOT.
2.Repeat Step 3 to 5 while PTR!=NULL:
3.Set TOP := TOP+1, STACK[Top]:=PTR.
4.If RIGHT[PTR]!=NULL, then:
Set TOP := TOP+1, Stack[Top]:=-
RIGHT[PTR].
[End of If structure]
5.Set PTR:=LEFT[PTR]
[End of step 3 Loop]
6.Set PTR:=STACK[Top], TOP := TOP-1.
7.Repeat while PTR>0:
a)Apply PROCESS to INFO[PTR].
b)PTR:=STACK[Top], TOP := TOP-1.
[End of Loop]
8.Repeat while PTR<0:
a) Set PTR:= -PTR.
b) Go to Step 2.
[End of If structure]
A B / C * D * E +
Data Structure and Algorithms Binary Tree

More Related Content

What's hot (20)

PPTX
Dfs
Ashish Ranjan
 
PPT
Graph traversal-BFS & DFS
Rajandeep Gill
 
PPTX
Balanced Tree (AVL Tree & Red-Black Tree)
United International University
 
PPT
Spanning trees
Shareb Ismaeel
 
PPTX
Binary Tree Traversal
Dhrumil Panchal
 
PDF
Red black tree
Dr Sandeep Kumar Poonia
 
PPTX
Graph representation
Tech_MX
 
PPTX
Binary Heap Tree, Data Structure
Anand Ingle
 
PPT
Heaps
Hafiz Atif Amin
 
PPSX
Data Structure (Tree)
Adam Mukharil Bachtiar
 
PDF
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
PPTX
B+ tree intro,uses,insertion and deletion
HAMID-50
 
PDF
Trees, Binary Search Tree, AVL Tree in Data Structures
Gurukul Kangri Vishwavidyalaya - Faculty of Engineering and Technology
 
PPTX
Insertion Sorting
FarihaHabib123
 
PPTX
Dfs presentation
Alizay Khan
 
PPTX
Graph traversals in Data Structures
Anandhasilambarasan D
 
PPTX
Design and Analysis of Algorithms
Arvind Krishnaa
 
PPTX
Threaded Binary Tree
khabbab_h
 
Graph traversal-BFS & DFS
Rajandeep Gill
 
Balanced Tree (AVL Tree & Red-Black Tree)
United International University
 
Spanning trees
Shareb Ismaeel
 
Binary Tree Traversal
Dhrumil Panchal
 
Red black tree
Dr Sandeep Kumar Poonia
 
Graph representation
Tech_MX
 
Binary Heap Tree, Data Structure
Anand Ingle
 
Data Structure (Tree)
Adam Mukharil Bachtiar
 
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
B+ tree intro,uses,insertion and deletion
HAMID-50
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Gurukul Kangri Vishwavidyalaya - Faculty of Engineering and Technology
 
Insertion Sorting
FarihaHabib123
 
Dfs presentation
Alizay Khan
 
Graph traversals in Data Structures
Anandhasilambarasan D
 
Design and Analysis of Algorithms
Arvind Krishnaa
 
Threaded Binary Tree
khabbab_h
 

Similar to Data Structure and Algorithms Binary Tree (20)

PPT
ds 10-Binary Tree.ppt
khitishlpu
 
PPT
Trees
Avila Rebello
 
PPT
Data Structure And Algorithms for Computer Science
ManishShukla712917
 
PPTX
Unit-VStackStackStackStackStackStack.pptx
nakshpub
 
PPT
binary tree
Shankar Bishnoi
 
PDF
Chapter 5_Trees.pdf
ssuser50179b
 
PPTX
7.tree
Chandan Singh
 
PPT
Admissions in india 2015
Edhole.com
 
PPTX
Unit 6 tree
Dabbal Singh Mahara
 
PPTX
binary tree.pptx
DhanushSrinivasulu
 
PDF
Lecture notes data structures tree
maamir farooq
 
PPTX
Basics of Binary Tree and Binary Search Tree.pptx
BhagyashriKotame2
 
PPT
Chap 5 Tree.ppt
shashankbhadouria4
 
PPTX
tree Data Structures in python Traversals.pptx
RupaRaj6
 
PPTX
Why Tree is considered a non-linear data structure?
mominkainat05
 
PPTX
Creating a Binary tree from a General Tree.pptx
DeepaThirumurugan
 
PPTX
Tree structure and its definitions with an example
prathwinidevadiga1
 
PDF
Binary Trees
Sadaf Ismail
 
PPTX
trees in data structure
shameen khan
 
PPT
Algorithm and Data Structure - Binary Trees
donotreply20
 
ds 10-Binary Tree.ppt
khitishlpu
 
Data Structure And Algorithms for Computer Science
ManishShukla712917
 
Unit-VStackStackStackStackStackStack.pptx
nakshpub
 
binary tree
Shankar Bishnoi
 
Chapter 5_Trees.pdf
ssuser50179b
 
Admissions in india 2015
Edhole.com
 
Unit 6 tree
Dabbal Singh Mahara
 
binary tree.pptx
DhanushSrinivasulu
 
Lecture notes data structures tree
maamir farooq
 
Basics of Binary Tree and Binary Search Tree.pptx
BhagyashriKotame2
 
Chap 5 Tree.ppt
shashankbhadouria4
 
tree Data Structures in python Traversals.pptx
RupaRaj6
 
Why Tree is considered a non-linear data structure?
mominkainat05
 
Creating a Binary tree from a General Tree.pptx
DeepaThirumurugan
 
Tree structure and its definitions with an example
prathwinidevadiga1
 
Binary Trees
Sadaf Ismail
 
trees in data structure
shameen khan
 
Algorithm and Data Structure - Binary Trees
donotreply20
 
Ad

More from ManishPrajapati78 (14)

PPT
Data Structure and Algorithms Queues
ManishPrajapati78
 
PPTX
Data Structure and Algorithms Merge Sort
ManishPrajapati78
 
PPTX
Data Structure and Algorithms The Tower of Hanoi
ManishPrajapati78
 
PPT
Data Structure and Algorithms Stacks
ManishPrajapati78
 
PPT
Data Structure and Algorithms Linked List
ManishPrajapati78
 
PPT
Data Structure and Algorithms Sorting
ManishPrajapati78
 
PPT
Data Structure and Algorithms Arrays
ManishPrajapati78
 
PPT
Data Structure and Algorithms
ManishPrajapati78
 
PPT
Data Structure and Algorithms Hashing
ManishPrajapati78
 
PPTX
Data Structure and Algorithms Graph Traversal
ManishPrajapati78
 
PPT
Data Structure and Algorithms Graphs
ManishPrajapati78
 
PPT
Data Structure and Algorithms Huffman Coding Algorithm
ManishPrajapati78
 
PPT
Data Structure and Algorithms Heaps and Trees
ManishPrajapati78
 
PPT
Data Structure and Algorithms AVL Trees
ManishPrajapati78
 
Data Structure and Algorithms Queues
ManishPrajapati78
 
Data Structure and Algorithms Merge Sort
ManishPrajapati78
 
Data Structure and Algorithms The Tower of Hanoi
ManishPrajapati78
 
Data Structure and Algorithms Stacks
ManishPrajapati78
 
Data Structure and Algorithms Linked List
ManishPrajapati78
 
Data Structure and Algorithms Sorting
ManishPrajapati78
 
Data Structure and Algorithms Arrays
ManishPrajapati78
 
Data Structure and Algorithms
ManishPrajapati78
 
Data Structure and Algorithms Hashing
ManishPrajapati78
 
Data Structure and Algorithms Graph Traversal
ManishPrajapati78
 
Data Structure and Algorithms Graphs
ManishPrajapati78
 
Data Structure and Algorithms Huffman Coding Algorithm
ManishPrajapati78
 
Data Structure and Algorithms Heaps and Trees
ManishPrajapati78
 
Data Structure and Algorithms AVL Trees
ManishPrajapati78
 
Ad

Recently uploaded (20)

PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 

Data Structure and Algorithms Binary Tree

  • 1. Binary trees: introduction (complete and extended binary trees), Memory representation (sequential, linked) Binary tree traversal: pre-order, in-order and post-order (traversal algorithms using stacks)
  • 2. A tree is a finite set of zero or more nodes such that: There is a specially designated node called the root. The remaining nodes are partitioned into n>=0 disjoint sets T1, ..., Tn, where each of these sets is a tree. We call T1, ..., Tn the subtrees of the root.
  • 3. Level and Depth K L E F B G C M H I J D A Level 0 1 2 3 node (13) degree of a node(shown by green number) leaf (terminal) nonterminal parent children sibling ancestor descendant level of a node height(depth) of a tree (4) 3 2 1 3 2 0 0 1 0 0 0 0 0
  • 4. Terminology The degree of a node is the number of subtrees of the node The degree of A is 3; the degree of C is 1. The node with degree 0 is a leaf or terminal node. A node that has subtrees is the parent of the roots of the subtrees. The roots of these subtrees are the children of the node. Children of the same parent are siblings. The ancestors of a node are all the nodes along the path from the root to the node.
  • 5. Tree Properties A B C D G E F IH Property Value Number of nodes Height Root Node Leaves Interior nodes Number of levels Ancestors of H Descendants of B Siblings of E degree of node A
  • 6. Binary Trees A special class of trees: max degree for each node is 2 Recursive definition: A binary tree is a finite set of nodes that is either empty or consists of a root and two disjoint binary trees called the left subtree and the right subtree.
  • 8. Samples of Trees A B A B A B C GE I D H F Complete Binary Tree Skewed Binary Tree E C D
  • 9. Maximum Number of Nodes in BT The maximum number of nodes on level i of a binary tree is 2i , i>=0. The maximum number of nodes in a binary tree of depth k is 2k -1, k>=1.
  • 10. Full BT vs. Complete BT A full binary tree of depth k is a binary tree of depth k having 2k -1 nodes, k>=1. A binary tree with n nodes and depth k is complete iff its nodes correspond to the nodes numbered from 1 to n in the full binary tree of depth k. A B C GE I D H F A B C GE K D J F IH ONML Full binary tree of depth 4Complete binary tree
  • 11. Complete Binary Tree If a complete binary tree with n nodes (depth= log└ n + 1 )┘ is represented sequentially, then for any node with index i, 1<=i<=n, we have: parent(i) is at i└ /2┘ if i!=1. If i=1, i is at the root and has no parent. leftChild(i) is at 2i if 2i<=n. If 2i>n, then i has no left child. rightChild(i) is at 2i+1 if 2i+1<=n. If 2i+1>n, then i has no right child.
  • 12. Extended Binary TreeA binary tree T is said to be a 2-tree or an extended binary tree if each node N has either 0 or 2 children. The nodes with 2 children are called internal nodes. The nodes with o children are called external nodes. A B C G D F A B C G D F Fig: Binary Tree T Fig: Extended 2-tree
  • 14. Linked Representation struct btnode { int data; btnode *left, *right; }; dataleft right data left right
  • 15. Binary Tree Traversals There are three standard ways of traversing a binary tree T with root R. These three algorithms, called: preorder inorder postorder
  • 16. Arithmetic Expression Using BT + * A * / E D C B preorder traversal + * * / A B C D E prefix expression inorder traversal A / B * C * D + E infix expression postorder traversal A B / C * D * E + postfix expression
  • 17. Preorder Traversal (recursive version) Algorithm: 1. Process the root R. 2. Traverse the left subtree of R in preorder. 3. Traverse the right subtree of R in preorder. Pseudo-Code: void preorder(btnode ptr) /* preorder tree traversal */ { if (ptr!=NULL) { cout<<ptr->data; preorder(ptr->left); predorder(ptr->right); } } + * * / A B C D E
  • 18. Inorder Traversal (recursive version) Algorithm: 1. Traverse the left subtree of R in inorder. 2. Process the root R. 3. Traverse the right subtree of R in inorder. Pseudo-Code: void inorder(btnode ptr) /* inorder tree traversal */ { if (ptr!=NULL) { inorder(ptr->left); cout<<ptr->data; indorder(ptr->right); } } A / B * C * D + E
  • 19. Postorder Traversal (recursive version) Algorithm: 1. Traverse the left subtree of R in postorder. 2. Traverse the right subtree of R in postorder. 3. Process the root R. Pseudo-Code: void postorder(btnode ptr) /* postorder tree traversal */ { if (ptr!=NULL) { postorder(ptr->left); postorder(ptr->right); cout<<ptr->data; } } A B / C * D * E +
  • 20. Preorder Traversal (using stack) PREORD(INFO, LEFT, RIGHT, ROOT) 1. Set TOP:= 1, STACK[1]:= NULL and PTR := ROOT. 2. Repeat Steps 3 to 5 while PTR != NULL: 3. Apply PROCESS to INFO[PTR]. 4. If RIGHT[PTR]!= NULL then Set TOP := TOP+1, and STACK[TOP]:= RIGHT[PTR]. 5. If LEFT[PTR]!= NULL then Set PTR:= LEFT[PTR]. Else Set PTR:= STACK[TOP] TOP:= TOP-1. [End of If structure] [End of step 2 Loop] 6. Exit. + * * / A B C D E
  • 21. Inorder Traversal (using stack) INORD(INFO, LEFT, RIGHT, ROOT) 1.Set TOP:= 1, STACK[1]:= NULL and PTR := ROOT. 2.Repeat while PTR != NULL: a) Set TOP:=TOP+1, STACK[TOP]:=PTR. b) Set PTR:= LEFT[PTR]. [End of loop] 3.Set PTR:=STACK[TOP], TOP:=TOP-1. 4.Repeat Steps 5 to 7 while PTR != NULL: 5.Apply PROCESS to INFO[PTR]. 6.If RIGHT[PTR]!= NULL, then: a) Set PTR:=RIGHT[PTR] b) Go to Step 2. [End of If structure] 7.Set PTR:=STACK[TOP] and TOP:=TOP-1. [End of step 4 Loop.] 8.Exit A / B * C * D + E
  • 22. Postorder Traversal (using stack) POSTORD(INFO, LEFT, RIGHT, ROOT) 1.Set TOP:= 1, STACK[1]:= NULL and PTR := ROOT. 2.Repeat Step 3 to 5 while PTR!=NULL: 3.Set TOP := TOP+1, STACK[Top]:=PTR. 4.If RIGHT[PTR]!=NULL, then: Set TOP := TOP+1, Stack[Top]:=- RIGHT[PTR]. [End of If structure] 5.Set PTR:=LEFT[PTR] [End of step 3 Loop] 6.Set PTR:=STACK[Top], TOP := TOP-1. 7.Repeat while PTR>0: a)Apply PROCESS to INFO[PTR]. b)PTR:=STACK[Top], TOP := TOP-1. [End of Loop] 8.Repeat while PTR<0: a) Set PTR:= -PTR. b) Go to Step 2. [End of If structure] A B / C * D * E +