11 12. Non Linear Data Structures
11 12. Non Linear Data Structures
Tushar B. Kute,
http://tusharkute.com
Choosing a Data Structure
• struct node
{
int data;
struct node *left;
struct node *right;
}
• The above structure can only be defined for the binary
trees because the binary tree can have utmost two children,
and generic trees can have more than two children.
• The structure of the node for generic trees would be
different as compared to the binary tree.
Tree: Application
A→B→D→E→C→F→G
Postorder Traversal
D→E→B→F→G→C→A
Inorder Traversal
D→B→E→A→F→C→G
Complexities of Tree Traversal
• Path
– A path can be defined as the sequence of nodes
that are followed in order to reach some
terminal node V from the initial node U.
• Closed Path
– A path will be called as closed path if the initial
node is same as terminal node. A path will be
closed path if V0=VN.
Graph Terminologies
• Simple Path
– If all the nodes of the graph are distinct with an
exception V0=VN, then such path P is called as
closed simple path.
• Cycle
– A cycle can be defined as the path which has no
repeated edges or vertices except the first and
last vertices.
Graph Terminologies
• Connected Graph
– A connected graph is the one in which some path
exists between every two vertices (u, v) in V.
There are no isolated nodes in connected graph.
• Complete Graph
– A complete graph is the one in which every node
is connected with all other nodes. A complete
graph contain n(n-1)/2 edges where n is the
number of nodes in the graph.
Graph Terminologies
• Weighted Graph
– In a weighted graph, each edge is assigned with
some data such as length or weight. The weight of
an edge e can be given as w(e) which must be a
positive (+) value indicating the cost of traversing
the edge.
• Digraph
– A digraph is a directed graph in which each edge of
the graph is associated with some direction and
the traversing can be done only in the specified
direction.
Graph Terminologies
• Loop
– An edge that is associated with the similar end points
can be called as Loop.
• Adjacent Nodes
– If two nodes u and v are connected via an edge e,
then the nodes u and v are called as neighbours or
adjacent nodes.
• Degree of the Node
– A degree of a node is the number of edges that are
connected with that node. A node with degree 0 is
called as isolated node.
Graph Representation
Web Resources
https://mitu.co.in
@mituskillologies http://tusharkute.com @mituskillologies
contact@mitu.co.in
tushar@tusharkute.com