Tree
Tree
Tree
Tree is a non-linear
linear data structure which organizes data in a hierarchical structure and this is a recursive
definition. Or a tree is a connected graph without any circuits. Or, if in a graph, there is one and only one
path between every pair of vertices, and then graph is called as a tree.
Example:
Tree Terminology-
The important terms related to tree data structure are
are-
Here,
Degree of node A = 2
Degree of node B = 3
Degree of node C = 2
Degree of node D = 0
So, the highest degree of a node among all the nodes of this tree is Degree(B
Degree(B)=3.
)=3. So, the degree of this tree
is 3.
7. Internal Node
The node which has at least one child is called as an internal node.
Internal nodes are also called as non-terminal nodes.
Every non-leaf
leaf node is an internal node.
Here, A,B,C,I,E is internal node.
8. Leaf Node
The node which does not have any child is called as a leaf node.
Leaf nodes are also called as external nodes or terminal nodes.
Here, G,J,K,H,D and F are leaf node.
9. Level
Height of node A = 3
Height of node B = 2
Height of J,K,D =0
11. Depth
Total number of edges from root node to a particular node is called as depth of that node.
node
Depth of a tree is the total number of edges from root node to a leaf node in the longest path.
Depth of the root node = 0
The terms “level” and “depth” are used interchangeably.
Depth of node A = 0
Depth of node B = 1
Depth of node C = 1
Depth of node J = 3
12. Forest: A collection of disjoint trees.
Types of Trees
Types of trees depend on the number of children a node has. There are two major tree types:
i. General Tree: A tree in which there is no restriction on the number of children a node has, is
called a General tree. Examples are Family tree, Folder Structure.
ii. Binary Tree: In a Binary tree, every node can have at most 2 children, left and right. In
diagram below, B & D are left children and C, E & F are right children.
Binary trees are further divided into many types based on its application.
Full Binary Tree: If every node in a tree has either 0 or 2 children, then the tree is called a
full tree. The tree in the above diagram is not a full binary tree as node C has only the right
child.
Perfect Binary tree: It is a binary tree in which all interior nodes have two children and all
leaves have the same depth or same level.
Balanced Tree: If the height of the left and right subtree at any node differs at most by 1,
then the tree is called a balanced tree.
Binary Search Tree: It is a binary tree with binary search property. Binary search property
states that the value or key of the left node is less than its parent and value or key of right
node is greater than its parent. And this is true for all nodes
Binary search trees are used in various searching and sorting algorithms. There are many variants of
binary search trees like AVL tree, B-Tree, Red-black tree, etc.
Ans.: a
39. Stack operations are[AP( SBL)-2016]
2016]
a) delete, insertion b) insertion, delete c) push,pop d)pop, raer Ans.: c