Data structures (Trees)
Data structures (Trees)
Instructor:
Ms.Dur-e-Shawar Agha
ROAD MAP
Introduction to Trees
President
+
VP VP
Personnel Marketing * 5
3 2
Director Director
Customer Sales
Relation
Applications of tree
o Mathematical expression
Basic terminology
The following image shows a tree, where the node A is the root node of the tree
while the other nodes can be seen as the children of A.
Contd
….
Root Node :- The root node is the topmost node in the tree hierarchy. In
other words, the root node is the one which doesn't have any parent.
Sub Tree :- If the root node is not null, the tree T1, T2 and T3 is called
sub-trees of the root node.
Leaf Node :- The node of tree, which doesn't have any child node, is
called leaf node. Leaf node is the bottom most node of the tree. There
can be any number of leaf nodes present in a general tree. Leaf nodes
can also be called external nodes.
Path :- The sequence of consecutive edges is called path. In the tree
shown in the above image, path to the node E is A→ B → E.
Contd
….
Ancestor node :- An ancestor of a node is any predecessor node on a
path from root to that node. The root node doesn't have any ancestors. In
the tree shown in the above image, the node F have the ancestors, B
and A.
Degree :- Degree of a node is equal to number of children, a node have.
In the tree shown in the above image, the degree of node B is 2. Degree
of a leaf node is always 0 while in a complete binary tree, degree of each
node is equal to 2.
Level Number :- Each node of the tree is assigned a level number in
such a way that each node is present at one level higher than its parent.
Root node of the tree is always present at level 0.
Types of Tree
Types of Tree