UNIT-5-2
UNIT-5-2
SYLLABUS
Graphs and their applications
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.
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. The path that starts and finishes at the same vertex is known as a cycle.
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 Terminology
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.
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.
– The out-degree of a vertex in a directed graph is the total number of outgoing edges, whereas the in-
degree is the total number of incoming edges.
– A vertex with an in-degree of zero is referred to as a source vertex, while one with an out-degree of
zero is known as sink vertex.
Types of graph
Two types-
1. Sequential representation (or, Adjacency matrix
representation)
2. Linked list representation (or, Adjacency list
representation)
1. Adjacency Matrix
• When you add a vertex that after introducing one or more vertices
or nodes, the graph's size grows by one, increasing the matrix's size
by one at the row and column levels.
Delete Vertex
• It begins at the root of the graph and investigates all nodes at the
current depth level before moving on to nodes at the next depth
level.
• DFS is a search technique for finding a node in a graph data structure that meets a set of
criteria.
• Depth First Traversal (or DFS) for a graph is similar to Depth First Traversal of a tree. The only
catch here is, that, unlike trees, graphs may contain cycles (a node may be visited twice). To
avoid processing a node more than once, use a boolean visited array. A graph can have more
than one DFS traversal.
• The depth-first search (DFS) algorithm traverses or explores data structures such as trees and
graphs. The DFS algorithm begins at the root node and examines each branch as far as
feasible before backtracking.
• To maintain track of the child nodes that have been encountered but not yet inspected, more
memory, generally a stack, is required.
• Depth-first search is an algorithm for traversing or searching tree or graph data structures.
The algorithm starts at the root node (selecting some arbitrary node as the root node in the
case of a graph) and explores as far as possible along each branch before backtracking.
Algorithm of depth-first search
Properties
• A spanning tree does not have any cycle.
• Any vertex can be reached from any other vertex.
Example
Minimum Spanning Tree
• One graph may have more than one spanning tree. If there are n
number of vertices, the spanning tree should have − number of
edges. In this context, if each edge of the graph is associated with a
weight and there exists more than one spanning tree, we need to
find the minimum spanning tree of the graph.
• This algorithm always starts with a single node and moves through several
adjacent nodes, in order to explore all of the connected edges along the
way.
• An optimization problem can be solved using Greedy if the problem has the
following property:
– At every step, we can make a choice that looks best at the moment, and we
get the optimal solution to the complete problem.
Prim’s algorithm for Minimum Spanning Tree
(MST)
• In the Dijkstra algorithm, we use a graph. we find the smallest path between two or many nodes.
• On social media sites, we use graphs to track the data of the users. liked showing preferred post
suggestions, recommendations, etc.
• Graphs are used in biochemical applications such as structuring of protein, DNA etc.
• First, analysis to determine structural properties of a network, such as the distribution of vertex degrees
and the diameter of the graph. A vast number of graph measures exist.
• Second, analysis to find a measurable quantity within the network, for example, for a transportation
network, the level of vehicular flow within any portion of it.
• Third, analysis of dynamic properties of network. Map of a country can be represented using a graph. Road
network, Air network or rail network can be represented using a graph. Connection among routers in a
communication network can be represented using a graph. Routing of a packet between two
communicating nodes can be done through the shortest path.
• Graph theory is useful in biology and conservation efforts where a vertex can represent regions where
certain species exist and the edges represent migration paths, or movement between the regions. This
information is important when looking at breeding patterns or tracking the spread of disease.
• Different activities of a project can be represented using a graph. This graph can be useful in project
scheduling.