Академический Документы
Профессиональный Документы
Культура Документы
Dr. D. P. Acharjya
Professor, SCOPE
24-Mar-17 Dr. D. P. Acharjya 1
Introduction to Trees
A connected acyclic graph is a tree.
A tree is a finite set of one or more
nodes such that
There is a specially designated node called root.
Remaining nodes are partitioned into n-disjoint
sets Ti, i = 1,2, , n where each Ti is a tree.
It is an efficient way of storing and
organizing data that is naturally
hierarchical.
24-Mar-17 Dr. D. P. Acharjya 2
Example of Tree
Sibling
Link
Leaf
Degree 1 Level 2
Level 3
Height 5 Level 4
Level 1
Level 2
Level 3
Level 4
Level 0 Nodes 1
Level 1 Nodes 2
Level 2 Nodes 4
Level 3 Nodes 8
Level 4 Nodes 16
Level 0 Nodes 1
Level 1 Nodes 2
Level 2 Nodes 4
Level 3 Nodes 8
Level 4 Nodes 12
Inorder
In this traversal, before visiting the root node, left
subtree of the root node is to be visited, then root
node and after right subtree of the root node will be
visited. (TlRTr)
Postorder
In this traversal left subtree of the root node is
visited first followed by right subtree and at end the
root node. (TlTrR)
Preorder traversal - *
+AB*C/DE
A B C /
Inorder traversal
AB+C*D/E D E
Postorder traversal
ABCDE/*+