Week 2 Graph Theory
Week 2 Graph Theory
Discrete Mathematics
MAHAM NOOR
Introduction
A graph is a set of points, called nodes or vertices, which are interconnected
by a set of lines called edges. The study of graphs, or graph theory is an
important part of a number of disciplines in the fields of mathematics,
engineering and computer science
What is a Graph?
If the degree of a vertex is even, the vertex is called an even vertex and if
the degree of a vertex is odd, the vertex is called an odd vertex.
Degree of a Graph −
The degree of a graph is the largest vertex degree of that graph. For the
above graph the degree of the graph is 3.
The Handshaking Lemma −
In a graph, the sum of all the degrees of all the vertices is equal to twice the
number of edges.
There are different types of graphs, which we will
learn in the following section.
Types of
Graphs
Null Graph
1. Adjacency Matrix
2. Adjacency List
Adjacency Matrix
An Adjacency Matrix A[V][V] is a 2D array of size V×V where V is the number of vertices in a
undirected graph. If there is an edge between Vx to Vy then the value of A[Vx][Vy]=1 and A[Vy]
[Vx]=1, otherwise the value will be zero. And for a directed graph, if there is an edge between Vx to
Vy, then the value of A[Vx][Vy]=1 , otherwise the value will be zero.
Adjacency Matrix of an
Undirected Graph
Let us consider the following undirected graph and construct the adjacency
matrix −
Adjacency Matrix of a
Directed Graph
Let us consider the following directed graph and construct its adjacency
matrix −
Adjacency List
In adjacency list, an array (A[V]) of linked lists is used to represent the graph G with V number of
vertices. An entry A[Vx] represents the linked list of vertices adjacent to the Vx−th vertex. The
adjacency list of the undirected graph is as shown in the figure below −
Many problems can be modeled using graphs with
Shortest Path weights assigned to their edges. How an airline
system can be modeled. We set up the basic graph
problem model by representing cities by vertices and flights
Dijkstra algorithm
by edges. Problems involving distances can be
modeled by assigning distances between the cities
to the edge. Problems involving flight time can be
modeled by assigning flight times to edges.
Problems involving fares can be modeled by
assigning fares to the edges.
Weighted Graphs Modeling an
Airline System
Problems involving distances can be modeled by assigning distances between the cities to the
edge.
Weighted Graphs Modeling an
Airline System
Problems involving distances can be modeled by assigning distances between the cities to the
edge.
Weighted Graphs Modeling an
Airline System
Problems involving distances can be modeled by assigning distances between the cities to the
edge.
Dijkstra’s Algorithm
Dijkstra’s Algorithm
Dijkstra’s Algorithm
Dijkstra’s Algorithm
Dijkstra’s Algorithm
Dijkstra’s Algorithm
Dijkstra’s Algorithm
Dijkstra’s Algorithm
Happy Learning
Maham Noor