Week 13
Week 13
CSO102
WEEK-13 (DRAFT)
GRAPH:
- a non-linear data structure consisting of vertices and edges
- the vertices are sometimes also referred to as nodes
- the edges are lines or arcs that connect any two nodes in the graph
Edges: Edges are drawn or used to connect two nodes of the graph. It can be ordered
pair of nodes in a directed graph. Edges can connect any two nodes in any possible way.
There are no rules. Sometimes, edges are also known as arcs. Every edge can be
labeled/unlabelled.
Representations of graphs:
● Adjacency Matrix
● Adjacency List
Adjacency Matrix Representation:
Adjacency List Representation:
Terminologies:
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.
Terminologies:
Cycle
A cycle can be defined as the path which has no repeated edges or vertices except the first and
last vertices.
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.
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.
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.
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.
Types of graphs:
Null Graph
Non-directed Graph
Directed Graph
Connected Graph
Disconnected Graph
Regular Graph
Complete Graph
Cyclic Graph
Acyclic Graph
Types of graphs:
Finite Graph
Infinite Graph
Bipartite Graph
Planar Graph
Simple Graph
Multi Graph
Euler Graph
Hamiltonian Graph
Adjacency Matrix:
● Consumes more space O(V2) . Even if the graph is sparse(contains less number of