Data Structures Module 3
Data Structures Module 3
Module-3
Module III: Trees: Concept of Trees, Tree terminologies, Binary tree: Complete
and Extended Binary tree, Expression trees, Representation of Binary Tree,
Traversing Binary Trees – Preorder, Inorder, Postorder. Binary Search Tree (BST):
Search, Insertion and Deletion operations, creating a Binary Search Tree. Graph:
Concept of Graph, Graph terminologies, Graph Traversal – BFS, DFS.
What is Tree? Explain various terms related to Trees
Tree: A Tree is a hierarchical collection of nodes or vertices, where each node
contains data as well as information about successor nodes.
Child Node: The successor node of a node is called its child node. In other
words, in a tree structure, a node coming under another node is its child.
Parent Node: The predecessor node of a node is called its parent. In other
words, in a tree structure, a node coming above another node is its parent. Every
ode will have only a single parent.
Root Node: A special node that has no parent node is called the root node.
Leaf node: A special node that has no child node is called a leaf node.
Siblings: The child nodes of the same parent are called siblings
Internal/external nodes: Leaf nodes are known as external nodes and non-leaf
nodes are known as internal nodes.
Depth: The depth of a vertex is the length of the simple path from the root to
that node.
Height of a tree: The height of a tree is the length of the longest path.
Forest: A forest is a set of disjoint trees.
Ordered tree: A rooted tree is a tree that has a root. An ordered tree is a rooted
tree in which there is an order among the children of each node.
Orchard: An orchard is an ordered set of ordered trees.
What are the four different types of Trees in Data Structure?
1. Ordinary tree: A tree in which there is no restriction on the number of
children or in the order of data in nodes.
2. Binary tree: A tree in which each node has a maximum of 2 child nodes.
When there are two child nodes, one of them is left node and the other
one is right node.
3. Binary Search Tree (BST): A binary tree in which each left sub tree has
data less than the current node and each right sub tree has data greater
than the current node.
4. Heaps: A tree in which all nodes have data greater than their child nodes
What is a full binary tree?
A full Binary tree is a special type of binary tree in which every parent
node/internal node has either two or no children. Full binary tree is also called
strictly binary tree.
5. A graph with few edges relative to the number of its vertices is called
sparse graph.
16.Parallel Edges: Two edges are said to be parallel if their end points are
the same.
Explain the DFS (Depth First Search) method of graph traversal with
an example
The systematic approach used in DFS is to move forward using unvisited
adjacent vertices until no further forward movement is possible. At this stage,
backtrack to the previous vertex and the process is repeated once again.
Example:
Consider the following graph
Step 1: Suppose we start with vertex A. The adjacent vertices are B,D,F,G and
H. Then we mode on to B .
Step 2: Adjacent vertices of B are C,E and F(other than A which has already
been visited). So we move on to C
Step 3: Adjacent vertices of C that are unvisited are D and E. We move on to
D. D has no other adjacent vertex depth-wise.
Step 4: We backtrack to the vertex C and move on to E which is an unvisited
adjacent vertex of C.
Step 5: There are no more adjacent vertices depth-wise.
Step 6: We backtrack to C, since the all adjacent vertices of C has already
been visited, we again backtrack to B.
Step 7: From B, we move on to F which is an unvisited adjacent node.
Step 8: We backtrack to B and again to A. The remaining unvisited adjacent
vertices are G and H.
Step 9: We move on to G and thus to H and the traversal is complete.
Example: