2. Contents
● Introduction to Graphs
● Representation of Graphs
● Weighted Graphs
● Non-weighted Graphs
● Directed Graphs
● Undirected Graphs
● Self-loops
● Multigraphs
● Real World Examples
3. Introduction to Graphs
● A graph G, consists of Vertices(V) and Edges(E).
● G = (V,E).
● V is the set of Vertices.
● E is the set of Edges.
4. Representation of Graphs
● Let V = {a, b, c}, and E = { { a, b }, { a, c } }.
a b
c
Set describing all the
vertices(or nodes) a, b,
and c.
Set describing an edge
between node a and c.
|V| = 3
|E| = 2
5. Weighted Graphs
● Weight or cost is a numerical value associated to every edge of a graph. We
encounter with it in real world, when we need to calculate shortest path between two
points, for example – when we see maps to find the shortest driving distance. The
path is chosen which has the minimum cost.
A
E
C
D
B
3
1
1
2
4
2
Shortest path between A & E : A -> D -> C -> E
8
4
6. Non-weighted Graphs
● In non weighted graphs, when we doesn’t have weights, all edges are considered
equal. The path which has less number of nodes is considered effective.
A
E
C
D
B
Shortest path between A & E : A -> B -> E
7. Undirected Graphs
● Undirected graphs have edges that do not have a direction. The edges indicate a two-
way relationship, in that each edge can be traversed in both directions.
A
B
D
C
8. Directed Graphs
● Directed graphs have edges with direction. The edges indicate a one-way relationship,
in that each edge can only be traversed in a single direction.
A
B
D
C
9. Self-loops
● Graphs created can have one or more self-loops, which are edges connecting a node
to itself.
A
B
D
C
10. Multigraphs
● Graphs can have multiple edges with the same source and target nodes, and the graph
is then known as a multigraph. A multigraph may or may not contain self-loops.
A
B
D
C
11. Real World Examples
● Social Graphs – Connections on LinkedIn.
● Path Optimization Algorithms – Google Maps.
● Routing Algorithms in Computer Networks – Routing IP Table in Router.
● Scientific Computations - Edge Chasing in Operating Systems.