Вы находитесь на странице: 1из 24

• Presented to:

Mam Mubeen Islam


• Presented by:
Anum Rafiq and Iqra Farheen
• Roll no:
391 and 422
• Class:
BS-IT(2nd)
Trees
Contents:

• 1- Components of trees
• 2- Definition of trees
• 3- Facts of trees
• 4- Example 1
• 5- Level visit
• 6- Depth first search
• 7- Types of tree
• 8- Binary tree
• 9- Complete binary tree
• 10- Full binary tree
• 11- Example 2
• 12- Representation
• 13- Reference based representation
• 14- List of figure
• 15- questions
List of figures: slide no:
• 1- Fig. 1 12
• 2-Fig. 2 13
• 3-Fig. 3 14
. 4-Fig. 4 15
• 5-Fig. 5 17
• 6-Fig. 6 18

• 7-Fig. 7 19
• 8-Fig. 8 20
• 9-Fig. 9 21
• 10-Fig. 10 22
Components of trees:

• Nodes / Vertex:

• Each nodes represents an object. that stores (lets


say) some number in it.
• Edge:

• It represents the relationship between two nodes.


Definition:

• In mathematics, more specifically graph theory, a


tree is a graph in which any two vertices are
connected by exactly one path . In other words, any
connected graph without cycles is a tree.

• It represents herarical relationship between


elements/objects.

• Each tree consist of nodes and edges.


Facts of trees:

• 1- G is connected and has no cycles

• 2- Each node represents an object. and it must hold


only one number in it.

• 3- Each edge represents relationship between two


nodes.

• 4- For any two nodes ,lets say u and v,


• If there is an edge pointing form u to v then u is called
parent node of v. and v is called child node of u and
they are represented as (u, v)
Continued...

• (a) Root:

if there is only one node without parent in a tree, then this


node is known as root or parent.
(b) leaves:

the node without child is called leave. otherwise they are called
internal node.
(c) siblings:

if two nodes have same parent ,they are called siblings


Continued…
• Ancestor:

• A node u is an ancestor of v. if u is parent of v, or parent of


parent…

• Descendant:

• A node v is called descendent of u. if v is child of u ,or v is called


child of u.
• Levels of nodes:
• There are different levels of nodes. and we can easily known ,at
what level our value is placed
• Height of tree:
Maximum levels among all nodes of tree is call its
height.
Example 1:
Level visit:
Depth first search (DFS):
Difference b/w tree and graph:
Types of trees:

• (a). Binary tree

• (b). Tree structure

• (c). Decision tree

• (d). Tree data structure

• (e). Traverse tree


Binary tree:

A binary tree is a tree in which


each node has at most two
children or less , left child
and right child.
Complete binary tree:

• It is a tree in which there is


one parent node on the left
side of the tree and it must
has two child nodes. On the
other hand in right side
there is one parent node and
has only one child.
Full binary tree:

• A full binary tree is a special


kind of complete binary tree
in which all leaves must be
an right level and each node
have two children.
Example 2:
Representation:
Reference based representation:
Questions:

(1). Difference b/w trees and graph?


(2). why we use trees in discrete mathematics?
(3). did we use trees now a days?
(4). does trees hold importance in computer
science field?
Any questions?