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

Data Structures Using C++ (B18EC4062)

This document introduces trees as a non-linear hierarchical data structure composed of nodes connected by edges. It defines key tree terminology like root node, parent node, child node, leaf node, subtree, ancestor node, and describes properties like degree, height, and depth of nodes. Trees are useful because unlike linear data structures, accessing data is faster as the data is stored non-sequentially. Common tree types discussed include general trees, binary trees, binary search trees, AVL trees, red-black trees, and n-ary trees.

Uploaded by

Ayushi Kumari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Data Structures Using C++ (B18EC4062)

This document introduces trees as a non-linear hierarchical data structure composed of nodes connected by edges. It defines key tree terminology like root node, parent node, child node, leaf node, subtree, ancestor node, and describes properties like degree, height, and depth of nodes. Trees are useful because unlike linear data structures, accessing data is faster as the data is stored non-sequentially. Common tree types discussed include general trees, binary trees, binary search trees, AVL trees, red-black trees, and n-ary trees.

Uploaded by

Ayushi Kumari
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Data Structures Using C++ (B18EC4062) 2020

Non-Linear Data Structures – Trees

Introduction:

 A tree is a non-linear hierarchical (arranged in order of rank) data structure that is a


collection of nodes connected by means of edges which are either directed or undirected.
 Elements are stored non-sequentially.
 One of the nodes is called the Root node (topmost node) and the rest of the nodes are called
the child nodes or leaf nodes of the root node.
 Each node can have many children but only one parent node.
 A sample basic tree is as shown below:

In the above diagram, A, B, C, D, E, F, G,H, I, J are all nodes.

Important Terminologies related to Trees:

 Edges: Link between two nodes. Each node is connected to the next node using edges. In the
above diagram, A node is connected to node B through a right edge and A node is connected
to node C is connected through left edge.
 Root Node: Topmost node of a tree is the root node. Each tree will have only one root node.
In above diagram Node A is the Root Node.
 Parent Node: Parent node is a node which is not the Root node. Parent node has an edge
upwards towards the parents. Parent node has a child node.
Node B is parent to Nodes D and E, Node C is parent to Nodes F and G, Node D is parent to
Node H and I, Node E is parent to Node J.
 Child Node: The node below a parent node which has an edge downwards is called the Child
node.
Node D and E are child node of Parent B, Node F and G are child nodes of Parent C, Nodes H
and I are child nodes of Parent D, J node is child node of Parent E.
 Leaf Node: Node which does not have any child nodes is called leaf node.
Nodes F, G, H, I and J are leaf nodes.

Dilip Chandra E, REVA University Page 1


Data Structures Using C++ (B18EC4062) 2020
 Subtree: Descendants of a node when the root is not NULL. A tree usually consists of a root
node and one or more subtrees.
In the figure above, (B-D, B-E), (C-F, C-G) and (D-H, D-I) are subtrees.
 Ancestor Node: Previous nodes on path from Root node to the current node.
In the above figure, Nodes A, B, and D are Ancestor Nodes of Node H.
 Key: Value of a node represents the key.
 Level: Represents the generation of the node. Root Node is always at level 0, its next child is
at level 1 and grandchild is at level 2.
 Traversing: Passing through nodes in a specific order.
 Path: Sequence of consecutive edges. In the above figure, the path to E is A->B->E.
 Degree: Degree of a node indicates the number of children a node has.
In figure above, the degree of node B is 2 and Degree of node E is 1.
 Height of a Node: is the number of edges on the longest path between that target node and
a leaf. Each node has a height associated but leaf node has no height associated.
In the above figure: the height of the node A is: 3 ( A->B->D->H or I) or (A->B->E->J)
 Depth of a Node: is the number of edges between the target node and the root.
In the figure above, Depth of Node D is 2 and Depth of Node I is 3.

Need for Tree Data Structure:

In other linear data structures like arrays, queues, stacks and linked list data is store sequentially. In
order to perform any operation in a linear data structure the time complexity increases with increase
in data size. Different tree data structures allow quicker and easier access to the data as it is a non-
linear data structure. Trees data structure represents the memory arrangement of a computer
system.

Types Of Trees:

Below is the list of Tree Data Structures:

a) General Tree:

b) Binary Tree.

c) Binary Search Tree

d) AVL Tree.

e) Red-Black Tree.

f) N-ary T

Dilip Chandra E, REVA University Page 2

You might also like