Professional Documents
Culture Documents
BSC 2 Unit III Tree
BSC 2 Unit III Tree
Trees and
Graphs:
A Tree is a non-linear data structure used to show the hierarchical relationship
among data.
Example for a Tree:
The OS of a computer system organizes files into
folders, subfolders and files. This can be viewed as the
tree.
Page | 1
Tree Terminology:
Forest and Trees
In graph theory a forest is an acyclic graph, and a tree is a connected acyclic graph; thus
a forest may consist of a set of trees.
Page | 2
Edges: edges connect a root with the roots of each sub tree.
Directed edge: The relationship between a parent and its children is a directed edge.
Undirected edge: An undirected edge extends in both directions (a parent and a child).
Directed path: A directed path is a sequence of directed edges e1, e2, ..., en.
Undirected path: An undirected path is a similar sequence of undirected edges.
Length of a path: The length of a path is the number of edges it contains.
Depth or level: The depth or level of a node is the length of a directed path from the
root to that node.
Height of a tree: The height of a tree is the length of the path from the root to a node at
the lowest level.
Page | 3