0% found this document useful (0 votes)
45 views

5.0 Tree Data Structure

Tree data structures organize data hierarchically with nodes connected by edges. They have a root node, internal nodes, and leaf nodes. Trees allow efficient searching and navigation of large amounts of data organized in a hierarchical manner. Common operations on trees include insertion, deletion, and traversal of nodes. Trees are non-linear data structures as data is not stored sequentially but arranged at multiple levels.

Uploaded by

Ch Ahtasham
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)
45 views

5.0 Tree Data Structure

Tree data structures organize data hierarchically with nodes connected by edges. They have a root node, internal nodes, and leaf nodes. Trees allow efficient searching and navigation of large amounts of data organized in a hierarchical manner. Common operations on trees include insertion, deletion, and traversal of nodes. Trees are non-linear data structures as data is not stored sequentially but arranged at multiple levels.

Uploaded by

Ch Ahtasham
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/ 3

What is tree data structure?

A tree data structure is a hierarchical structure that is used to represent and


organize data in a way that is easy to navigate and search. It is a collection of
nodes that are connected by edges and has a hierarchical relationship between the
nodes.
This data structure is a specialized method to organize and store data in the
computer to be used more effectively. It consists of a central node, structural
nodes, and sub-nodes, which are connected via edges. We can also say that tree
data structure has roots, branches, and leaves connected with one another.

Basic Terminologies In Tree Data Structure:


 Parent Node: The node which is a predecessor of a node is called the parent
node of that node. {B} is the parent node of {D, E}.
 Child Node: The node which is the immediate successor of a node is called
the child node of that node. Examples: {D, E} are the child nodes of {B}.
 Root Node: The topmost node of a tree or the node which does not have any
parent node is called the root node. {A} is the root node of the tree. A non-
empty tree must contain exactly one root node and exactly one path from the
root to all other nodes of the tree.
 Leaf Node or External Node: The nodes which do not have any child nodes
are called leaf nodes. {K, L, M, N, O, P, G} are the leaf nodes of the tree.
 Ancestor of a Node: Any predecessor nodes on the path of the root to that
node are called Ancestors of that node. {A,B} are the ancestor nodes of the
node {E}
 Descendant: Any successor node on the path from the leaf node to that
node. {E,I} are the descendants of the node {B}.
 Sibling: Children of the same parent node are called siblings. {D,E} are called
siblings.
 Level of a node: The count of edges on the path from the root node to that
node. The root node has level 0.
 Internal node: A node with at least one child is called Internal Node.
 Neighbour of a Node: Parent or child nodes of that node are called neighbors
of that node.
 Subtree: Any node of the tree along with its descendant.

Representation of a Node in Tree Data Structure:


struct Node
{
int data;
struct Node *first_child;
struct Node *second_child;
struct Node *third_child;
.
.
.
struct Node *nth_child;
};

Basic Operation Of Tree Data Structure:


 Create – create a tree in the data structure.
 Insert − Inserts data in a tree.
 Search − Searches specific data in a tree to check whether it is present or not.
 Traversal:
 Preorder Traversal – perform Traveling a tree in a pre-order
manner in the data structure.
 In order Traversal – perform Traveling a tree in an in-order
manner.
 Post-order Traversal –perform Traveling a tree in a post-order
manner.
Why Tree is considered a non-linear data structure?
The data in a tree are not stored in a sequential manner i.e., they are not stored
linearly. Instead, they are arranged on multiple levels or we can say it is a
hierarchical structure. For this reason, the tree is considered to be a non-linear
data structure.

Properties of Tree Data Structure:


 Number of edges: An edge can be defined as the connection between two
nodes. If a tree has N nodes then it will have (N-1) edges. There is only one
path from each node to any other node of the tree.
 Depth of a node: The depth of a node is defined as the length of the path from
the root to that node. Each edge adds 1 unit of length to the path. So, it can
also be defined as the number of edges in the path from the root of the tree to
the node.
 Height of a node: The height of a node can be defined as the length of the
longest path from the node to a leaf node of the tree.
 Height of the Tree: The height of a tree is the length of the longest path from
the root of the tree to a leaf node of the tree.
 Degree of a Node: The total count of subtrees attached to that node is called
the degree of the node. The degree of a leaf node must be 0. The degree of a
tree is the maximum degree of a node among all the nodes in the tree.
Application of Tree Data Structure:
 File System: This allows for efficient navigation and organization of files.
 Compiler Design: In compiler design, a syntax tree is used to represent the
structure of a program.
 Database Indexing: B-trees and other tree structures are used in database
indexing to efficiently search for and retrieve data.
Advantages of Tree Data Structure:
 Tree offer Efficient Searching Depending on the type of tree, with average
search times of O(log n) for balanced trees like AVL.
 Trees provide a hierarchical representation of data, making it easy to organize
and navigate large amounts of information.

You might also like