Non Linear Data Structure
Non Linear Data Structure
Advantages:
➢ Uses memory efficiently as contiguous memory is not
required for allocating data items
Disadvantages:
➢ Overhead of the link to the next data item
Tree Definition
➢ Tree data structure is a collection of data (Node) which is
organized in hierarchical structure recursively
➢ In tree data structure, every individual element is called as
Node. Node in a tree data structure stores the actual data
of that particular element and link to next element in
hierarchical structure
➢ In a tree data structure, if we have N number of nodes then
we can have a maximum of N-1 number of links
1) NODE = 11
2) LINKS =11-1=10
Note
A ROOT NODE
Edge
EDGE
Parent
➢ In a tree data structure, the Node which is predecessor
of any node is called as PARENT NODE.
➢ In simple words, the node which has branch from it to
any other node is called as parent node.
➢ Parent node can also be defined as "The node which
has child / children".
A Here ,
A, B, C , E, G are
PARENT NODE
B C
E G
Child
➢ In a tree data structure, the node which is descendant of
any node is called as Child Node
➢ In simple words, The node which has a link from its parent
node is called as child node.
➢ In a tree, any parent node can have any number of child
nodes.
➢ In a tree, all the nodes except root are child nodes.
A Here,
B and C – Children of A
B C D, E, F – Children of B
D E F G H G and H – Children of C
K – Child of G
I J K
I and J – Children of E
Siblings
Here,
B and C – SIBLINGS
D, E, F – SIBLINGS
G and H – SIBLINGS
I and J – SIBLINGS
Leaf Node
Here,
D, F, I, J, K, H are
LEAF NODE
D F H
I J K
Internal Nodes
➢ In a tree data structure, The node which has at least one
child is called as an internal node
➢ In simple words, Internal node is a node with at least one
child
➢ Nodes other than leaf nodes are called as Internal Nodes.
➢ Root node is also called as internal node, if tree has more then
one node
➢ Internal nodes are also called as Non-terminal nodes.
Here,
A, B, C, E, G are
INTERNAL NODES
Degree
➢ In a tree data structure, the total number of children of a
node is called as DEGREE of that Node.
➢ In simple words, Degree of a node is the total number of
children it has
➢ The highest degree of a node among all the nodes in the
tree is called as Degree of a tree
Here,
▪ Degree of node A = 2
▪ Degree of node B = 3
▪ Degree of node C = 2
▪ Degree of node D = 0
▪ Degree of node E = 2
▪ Degree of node F = 0
Level
➢ In a tree data structure, the root node is said to be at
Level 0 and the children of root node are at Level 1 and
the children of the nodes which are at Level 1 will be at
Level 2 and so on...
➢ In simple words, In a tree each step from top to bottom is
called as a Level and the Level count starts with '0' and
incremented by one at each level (Step).
LEVEL -- 00
LEVEL
LEVEL - 1
LEVEL - 2
LEVEL - 3
Height
➢ In a Tree data structure , The total number of edges from
leaf node to a particular node in the longest path is called
as HEIGHT of that Node.
➢ In a tree, Height of the root node is said to be Height of
the tree.
➢ In a tree, Height of all leaf node is 0
Here,
Height of node A = 3
Height of node B = 2
Height of node C = 2
Height of node D = 0
Height of node E = 1
Height of node F = 0
Depth
➢ In a tree data structure, the total number of edges from
root node to a particular node is called as DEPTH of that
Node.
➢ Depth of a tree is the total number of edges from root node
to a leaf node in the longest path is said to be DEPTH of
that node
➢ Depth of the root node is 0
Here,
Depth of node A = 0
Depth of node B = 1
Depth of node C = 1
Depth of node D = 2
Depth of node E = 2
Depth of node F = 2
Path
Here,
▪ PATH between A and J is
A-B-E-J
Here,
▪ B, D ,E, F, I, J form one
subtree
▪ C, G, H, K forms another
Subtree
▪ E, I, J forms another
subtree
BINARY TREE
B C
D E F G
BINARY TREE
➢ Root Node:
❖ Node at the “top” of a tree - the one from which all
operations on the tree commence.
❖ The root node may not exist (a NULL tree with no
nodes in it) or have 0, 1 or 2 children in a binary tree.
➢ Leaf Node:
❖ Node at the “bottom” of a tree - farthest from the root.
❖ Leaf nodes have no children.
➢ Complete Tree: Tree in which each leaf is at the same
distance from the root i.e. all the nodes have maximum two
subtrees.
➢ Height: Number of nodes which must be traversed from the
root to reach a leaf of a tree.
GRAPHS