0% found this document useful (0 votes)
2 views21 pages

DS 19-AM Tree _GA 094930

A tree is a non-linear data structure that organizes data hierarchically, consisting of nodes connected by edges. Key terminology includes root, edge, parent, child, siblings, leaf nodes, internal nodes, ancestors, degree, height, depth, level, path, branch, and sub-trees. There are different types of trees, such as general trees with no limit on children and binary trees where each node has at most two children.

Uploaded by

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

DS 19-AM Tree _GA 094930

A tree is a non-linear data structure that organizes data hierarchically, consisting of nodes connected by edges. Key terminology includes root, edge, parent, child, siblings, leaf nodes, internal nodes, ancestors, degree, height, depth, level, path, branch, and sub-trees. There are different types of trees, such as general trees with no limit on children and binary trees where each node has at most two children.

Uploaded by

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

Tree Definition

Tree is a non-linear data structure which


organizes data in hierarchical structure .
OR
Tree is a non-linear collection of data item
called node where each node connected by
edges
Tree terminology...

1.Root:
 The first node is called as Root Node.
 Every tree must have root node, there must be only
one root node.
 Root node doesn't have any parent.
2. Edge

It’s a connection between two node.

In a tree data structure, the connecting link between
any two nodes is called as EDGE. In a tree with 'N'
number of nodes there will be a maximum of 'N-1'
number of edges.
3. 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".

Predecessor ,predecessor of B & C is A.
4. Child

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.

Also called Successor ..Successor of A is B and C.
5. Siblings

The nodes with same parent are called as
Sibling nodes.
6. Leaf Node

The node which does not have a child is called as
LEAF Node.

The leaf nodes are also called as External Nodes or
'Terminal' node.
7. Internal Nodes

An internal node is a node with atleast one child.

Nodes other than leaf nodes are called as Internal Nodes.

The root node is also said to be Internal Node if the tree has
more than one node. Internal nodes are also called as 'Non-
Terminal' nodes.
6. Ancestor
In a tree, an ancestor of a node is any node that
lies on the path from the root to that node,
excluding the node itself.

The root node is an ancestor of all other
nodes.

A node can have multiple ancestors, all the
way up to the root. Ancestors of D =B , A
Ancestors of K =G , C, A
Ancestors of A = None (it’s the
root)
8. Degree

The number of immediate children a node has.

In a tree data structure, the total number of
A DEGREE
children of a node is called as leaf node
of has
that degree
Node. 0.

Degree of A = 2 (B, C)

Degree of B = 2 (D, E,F)

Degree of E = 2(I, J)

Degree of I ,J,K,H = 0 (leaf node)


10. Height

the total number of egdes 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.
11. Depth

In a tree data structure, the total number of egdes
from root node to a particular node is called as DEPTH
of that Node.
9. 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 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).
12. Path/ Branch

Starting from root node and
ending on leaf node.

In a tree data structure, the
sequence of Nodes and Edges
from one node to another
node is called as PATH
A-B-D A-C-G-K
between that two Nodes. A-B-E-I A-C-H
A-B-E-J
A-B-F
13. Sub Tree

Every child node will form a subtree on its parent node.
Type of Trees
• General • Binary tree
tree

Different types are used for different


things
To improve speed
To improve the use of available
memory
To suit particular problems
General Tree
• A general tree is a data structure in that each node can have infinite
number of children(no limitation of child node) .
• OR A General Tree is a hierarchical data structure in which each node
can have zero or more children (not limited to 2).
• In general tree, root has in-degree 0 and maximum out-degree n.
• Height of a general tree is the length of longest path from root to the
leaf of tree. Height(T) = {max(height(child1) , height(child2) , …
height(child-n) ) +1}
Properties:
• No limit on the number of children.

• Root node is the topmost node.

• Commonly used to represent organization charts, file


systems, etc.
Binary tree

• A Binary Tree is a tree in which each node has at most two children — called the left and
right child.
• OR A Binary tree is a data structure in that each node has at most two nodes left and right
• In binary tree, root has in-degree 0 and maximum out-degree 2.
• In binary tree, each node have in-degree one and maximum out-degree 2.
• max 2 ,min 0 or 1 node.
General (Non-Binary) Trees

• Nodes can have any number of children


Chapter 8: Trees

You might also like