0% found this document useful (0 votes)
10 views35 pages

Chapter - 10: Tree Part-1

This document provides an overview of tree data structures in computer science, defining a tree as a connected graph without simple circuits. It explains various tree terminologies such as root, parent, child, leaf, and internal node, along with properties and types of trees, including binary trees, full binary trees, and complete binary trees. Additionally, it discusses the relationships between nodes, such as ancestors and descendants, and presents theorems related to full binary trees.

Uploaded by

emon64646
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)
10 views35 pages

Chapter - 10: Tree Part-1

This document provides an overview of tree data structures in computer science, defining a tree as a connected graph without simple circuits. It explains various tree terminologies such as root, parent, child, leaf, and internal node, along with properties and types of trees, including binary trees, full binary trees, and complete binary trees. Additionally, it discusses the relationships between nodes, such as ancestors and descendants, and presents theorems related to full binary trees.

Uploaded by

emon64646
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/ 35

CHAPTER - 10

Tree
Part-1
Nature View of a Tree

Leaves

Branches

Root

2
Computer Scientist’s View

3
Definition

A connected graph that contains no simple circuits is called a tree.

4
Cont.

Which of the graphs show in figure are trees?

5
Cont.

§ G1 and G2 are trees, because both are connected graphs with


no simple circuits.
§ G3 is not a tree because e, b, a, d, e is a simple circuit in this
graph.
§ Finally, G4 is not a tree because it is not connected.
6
Cont.

Computers”R”Us

Sales Manufacturing R&D

US International Laptops Desktops

Europe Asia Canada

7
Applications of Tree

8
Rooted Tree

A rooted tree is a tree in which one vertex has been designated


as the root and every edge is directed away from the root.

Fig: A tree and rooted trees formed by designating two different roots.

9
Tree terminology

Tree Structure:

(1). Root (2). Parent, Children, Leaf (3). Internal node, External
Node (4). Degree of a Node and Tree (5). Path (6). Level
(7). Siblings (8). Ancestor, Descendant.

10
Cont.

Root
The node without parent is called root node. Every tree must
have root node. We can say that root node is the origin of tree
data structure. In any tree, there must be only one root node.
We never have multiple root nodes in a tree.

11
Cont.

Edge
In a tree data structure, the connecting link between any two
nodes is called as edge. In a tree with 'N' number of nodes
there will be a maximum of 'N-1' number of edges.

12
Cont.

Parent:
In a tree data structure, the node which is predecessor/ancestor
of any node is called as parent node. in simple words, the node
which has branch from it to any other node is called as parent
node. parent node can also be defined as "the node which has
child / children".

13
Cont.

Child
In a tree data structure, the node which is descendant of any
node is called as child node. In simple words, the node
which has a link from its parent node is called as child node.
In a tree, any parent node can have any number of child
nodes. In a tree, all the nodes except root are child nodes.

14
Cont.

Leaf
In a tree data structure, the node which does not have a child
is called as leaf node. In simple words, a leaf is a node with
no child.
In a tree data structure, the leaf nodes are also called as
external nodes. External node is also a node with no child. In
a tree, leaf node is also called as ‘terminal' node.

15
Cont.

Internal Node
In a tree data structure, the node which has at least one child is
called as internal node. In simple words, an internal node is a node
with at least one child.
In a tree data structure, nodes other than leaf nodes are called as
internal nodes. The root node is also said to be internal node if the
tree has more than one node. Internal nodes are also called as 'non-
terminal' nodes.

16
Cont.

Degree
In a tree data structure, the total number of children of a
node is called as degree of that node. In simple words,
the degree of a node is total number of children it has.
The highest degree of a node among all the nodes in a
tree is called as 'degree of tree‘.

17
Cont.

Level
In a tree data structure, the root node is said to be at Level 0
and the children of root node are at Level 1 and the children of
the nodes which are at Level 1 will be at Level 2 and so on...
In simple words, in a tree each step from top to bottom is
called as a Level and the Level count starts with '0' and
incremented by one at each level (Step).

18
Cont.

Sub Tree
In a tree data structure, each child from a node forms a subtree
recursively. Every child node will form a subtree on its parent
node.

19
Cont.

Siblings
In a tree data structure, nodes which belong to same parent
are called as siblings. In simple words, the nodes with same
parent are called as sibling nodes.

20
Cont.

Ancestor: The ancestors of a node are all the nodes along the path
from node to the root node. [parent, grandparent, grand-grandparent, etc.]

If node A is an
ancestor of node B
then node B is a
descendant of node A.

21
Cont.

Descendant: The descendent of a node are all the nodes along the
path from node to the leaf node. [child, grandchild, grand-grandchild, etc.]

If node A is an
ancestor of node B
then node B is a
descendant of node A.

22
Cont.

Path
In a tree data structure, the sequence of nodes and edges from
one node to another node is called as path between that two
nodes.

23
Cont.

24
Cont.

Tree Property Value


Number of nodes 9
Level 5
Root Node A
Leafs C, D, F, H, I
Interior nodes A, B, E, G
Ancestors of H G, E, B, A
Descendants of B D, E, F, H, G, I
Siblings of E D, F
Left subtree of A
Degree of this tree 3

25
Binary Tree

❖In a normal tree, every node can have any number of


children. Binary tree is a special type of tree data
structure in which every node can have a maximum of
2 (0, 1 or 2) children. One is known as left child and
the other is known as right child.
❖A tree in which every node can have a maximum of
two children is called as Binary Tree.
Parent

Left child Right child


26
Cont.

In a binary tree, every node can have either 0 children or 1 child


or 2 children but not more than 2 children.

27
Cont.

What is the max nodes at some level L?


The max nodes at level L is 2L where L=0,1,2, ...,L-1

28
Binary Tree Terminology

❖Left Child: The left child of node n is a node directly


below and to the left of node n in a binary tree.
❖Right Child: The right child of node n is a node directly
below and to the right of node n in a binary tree.
❖Left Subtree: In a binary tree, the left subtree of node n
is the left child (if any) of node n plus its descendants.
❖Right Subtree: In a binary tree, the right subtree of
node n is the right child (if any) of node n plus its
descendants.

29
Full Binary Trees

Here are two important types of binary trees. Note that the
definitions, while similar, are logically independent.
Full Binary Tree: A full binary tree (sometimes proper binary
tree) is a tree in which every node other than the leaves has two
children.

30
Properties of Trees

Theorem: Let T be a nonempty, full binary tree Then:


(a) If T has I internal nodes, the number of leaves is L = I + 1.
(b) If T has I internal nodes, the total number of nodes is N = 2I + 1.
(c) If T has a total of N nodes, the number of internal nodes is
I = (N – 1)/2.
(d) If T has a total of N nodes, the number of leaves is L = (N + 1)/2.
(e) If T has L leaves, the total number of nodes is N = 2L – 1.
(f) If T has L leaves, the number of internal nodes is I = L – 1.

31
Cont.

(a) If T has I internal nodes, the number of


leaves is L = I + 1 = 3 + 1=4.
(b) If T has I internal nodes, the total number
of nodes is N = 2I +1 = 2*3 + 1=7.
(c) If T has a total of N nodes, the number of
internal nodes is I= (N–1)/2 = (7–1)/2 = 3.
(d) If T has a total of N nodes, the number of
leaves is L = (N + 1)/ = (7 + 1)/2 = 4.
(e) If T has L leaves, the total number of
nodes is N = 2L – 1 = 2*4 – 1=7.
(f) If T has L leaves, the number of internal
nodes is I = L – 1 = 4 – 1=3.

32
Complete binary tree

A binary Tree is complete binary Tree if all levels are completely


filled except possibly the last level and the last level has all keys
as left as possible

33
Perfect Binary tree

A Binary tree is Perfect Binary Tree in which all internal nodes


have two children and all leaves are at same level.

34
Extended Binary Trees: 2-Trees

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.
In such case, the nodes with 2 children are called internal nodes,
and the nodes with 0 children are called external nodes.
Sometimes the nodes are distinguished in diagrams by using circles
for internal nodes and squares for external nodes.

35

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy