0% found this document useful (0 votes)
14 views16 pages

Graph

Uploaded by

Shayan Raza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views16 pages

Graph

Uploaded by

Shayan Raza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 16

Objectives

• Today’s lecture objectives include:

– Graph introduction

– Directed vs. Undirected graph

– Few graph terminologies

– Bipartite Graph

– Adjacency Matrix

Data Structures & Algorithms 1


Graph – Introduction
• A graph G = (V, E) is composed of:

V: set of vertices

E: set of edges connecting the vertices in V


• An edge e = (u, v) is a pair of vertices

• Example:
V = {a, b, c, d, e}
E = {(a, b), (a, c),
(a, d), (b, e),
(c, d), (c, e),
(d, e)}

Data Structures & Algorithms 2


Graph – Introduction…
Example: The following picture is
• Edges connect two
a graph. List its vertices and edges.
vertices.
A
• Edges only intersect at D
vertices.
C
• Edges joining a vertex
to itself are called
loops.

B
Data Structures & Algorithms 3
Graph – Introduction…
Example
• This is also a graph. The vertices just happen to have people’s
names (e.g., first character).
• Such a graph could represent friendships (or any kind of
relationship).
F B L

R A P

Data Structures & Algorithms 4


Graph – Introduction…
• Now check out the graph below.
• What can we say about it in comparison to the previous figure?

L R

F
Previous figure
A F B L
B
P Z Z

R A P
Data Structures & Algorithms 5
Graph – Introduction…
Moral of the Story
• One graph may be drawn in (infinitely) many ways, but it always
provides us with the same information.
• Graphs are a structure for describing relationships between
objects.
– The vertices denote the objects and the edges represent the relationship.

Data Structures & Algorithms 6


Directed vs. Undirected graphs
• When the edges in a graph have no direction, the graph
is called undirected. For example, Graph1
• When the edges in a graph have a direction, the graph is
called directed (or digraph). For example, Graph2

Warning: if the graph is directed, the order


of the vertices in each edge is important !!
Data Structures & Algorithms 7
Trees vs. Graphs
• Trees are special cases of graphs!!

Data Structures & Algorithms 8


Graphs Terminologies
• Adjacent nodes: two nodes are adjacent if they are
connected by an edge
5 adjacent to 7

7 is adjacent from 5

• Path: a sequence of vertices that connect two nodes in a


graph
• Complete graph: a graph in which every vertex is directly
connected to every other vertex

Data Structures & Algorithms 9


Graphs Terminologies…
• Weighted graph: a graph in which each edge carries a
value

Data Structures & Algorithms 10


Subgraphs
• Notice that the 2-cube occurs

• inside the 3-cube

• In other words, G1 is a subgraph of G2 :

• DEF: Let G = (V,E ) and H = (W,F ) be graphs. H is said to


be a subgraph of G, if W  V and F  E.

• Q: How many G1 subgraphs does G2 have?

Data Structures & Algorithms 11


Subgraphs…
• A: Each face of G2 is a G1 subgraph so the answer is 6, as
this is the number of faces on a 3-cube:

Data Structures & Algorithms 12


Adjacency Matrix
• For a digraph G = (V,E ) define matrix AG by:
• Value at i th row and j th column is
– 1 if i th vertex connects to j th vertex (i  j )
– 0 otherwise

R digraph(R) MR

2 1 1 1 1
 
1 1 0 1 1 1
1 3 
2 2 0 0 1 1
3 3  
0 0 0 1
4 4 4 
Data Structures & Algorithms 13
Adjacency Matrix
Q: What is the adjacency matrix?

1 4 3

0 3 0 1
 
A: 0 1 2 0
0 1 2 0
 
0 0 0 0 

Data Structures & Algorithms 14
Graph Applications
• Modelling a road network with vertices as towns and edge costs as
distances.
• Modelling a water supply network.

• Dynamically modelling the status of a set of routes by which traffic might


be directed over the Internet.
• Minimising the cost and time taken for air travel when direct flights don't
exist between starting and ending airports.
• Using a directed graph to map the links between pages within a website
and to analyse ease of navigation between different parts of the site.

Data Structures & Algorithms 15


Summary
• Graph introduction

• Directed vs. Undirected graph

• Few graph terminologies

• Bipartite Graph

• Adjacency Matrix

Data Structures & Algorithms 16

You might also like