Lecture 3 Trees in Data Structure
Lecture 3 Trees in Data Structure
Lecture 3 Trees in Data Structure
Structure
Lecture 2
Introduction
• Tree is a nonlinear hierarchical data structure, comprising
of a collection of entities known as nodes.
• It connects each node in the tree data structure using
"edges”, both directed and undirected.
Why tree in Data Structures
• The non-linear structure of trees enhances the data
storing, data accessing, and manipulation processes by
employing advanced control methods traversing through
it.
• Unlike arrays, linked-list, stacks, and queues with linear
data structures (data stored in sequential order), the time
complexity increases with increasing data size to perform
operations like insertion and deletion on these linear data
structures.
Terminologies used in Tree Data
Structure
• Tree Node: A node is a structure that contains a key or value
and pointers in its child node in the tree data structure.
• Syntax for defining tree node
• struct node
• {
• int data;
• struct node *leftchild;
• struct node *rightchild;
• }
Terminologies Cont’d
• Root is the first node of the tree or the initial node of the
tree in data structures.
• Edge: The connecting link of any two nodes.
• Parent is the predecessor of any node or a node with a
branch from itself to any other successive node.
• Child is a descendant of any node.
• Note: any number of parent nodes can have any number
of child nodes
Terminologies Cont’d
• Sibling: A nodes that belong to the same parent
• Leaf: A node with no child (known as external or terminal
nodes).
• Internal Nodes: Have at least one child node (nodes other
than leaf nodes are internal nodes).
• Degree: the total number of children of a node.
Level