Graph Theory
Fall 2023
COURSE OUTLINE
Introduction to Graph Theory
Basic definitions
computer representations and properties of Graph
Data structure for representing Graphs
Fundamental theorem of Graph Theory
Isomorphic and Special Graphs
Properties of Trees and Forests
Binary tree, Balanced binary tree
Directed and Undirected rooted tree
Minimum Spanning Tree algorithms and implementation
Path and Distance in graphs
Shortest path algorithms and implementation
Cycle and distance in weighted graph and digraphs
COURSE OUTLINE…
Distance algorithms and implementation
Eulerian graphs and Hamiltonians graphs with applications
Flow networks, Max-flow Min-cut Theorem
Graph colouring, Edge colouring
Planar graphs, Four colour theorem
Deadlock of computer system
Matching Algorithms
Dominance & Ramsey theory
Outline for today’s Lecture
Introduction to Graph Theory
Basic definitions
computer representations and properties of Graph
Data structure for representing Graphs
Lecture 01
Introduction to Graph Theory
The basic idea of graphs were first introduced in the 18th century by Swiss
mathematician Leonhard Euler.
His attempts & eventual solution to the famous Konigsberg bridge problem depicted
below are commonly quoted as origin of graph theory:
Lecture 01
Konigsberg geographical layout is composed of four main bodies of land connected
by a total of seven bridges. The question posed to Euler was straightforward: was
it was possible to take a walk through the town in such a way as to cross over
every bridge once, and only once (known as a Euler walk)?
Lecture 01
Euler, recognizing that the relevant constraints were the four bodies of land & the
seven bridges, drew out the first known visual representation of a modern graph.
Lecture 01
Applications of Graph Theory
The branch of math known as graph theory remained undeveloped for
decades. In modern times, however, it’s application is finally exploding.
Graph Theory is ultimately the study of relationships. Given a set of nodes
& connections, which can abstract anything from city layouts to computer
data.
Networking, Database, Data organization
Lecture 01
In software engineering, they’re known as a fairly common data structure
named decision trees.
Over in the world of electrical engineering, an entire discipline revolves
around the creation, calculation, & maintenance of multi-part electric
circuits — often diagrammed following graph theory principles.
Meanwhile in the realm of molecular biology, scientists extrapolate
prediction models for tracking the spread of diseases or breeding patterns.
Lecture 01
• Cost of wiring electronic components
• Shortest route between two cities.
• Shortest distance between all pairs of cities in a road atlas.
• Matching / Resource Allocation
• Task scheduling
• In Operating systems to model resource handling (deadlock problems)
Lecture 01
Basic Terminologies/types of Graph
Graph
Informally a graph is a set of nodes joined by a set of lines or arrows.
• A graph is a non-empty set of points called vertices and a set of line
segments joining pairs of vertices called edges.
• Formally, a graph G consists of two finite sets:
(i) A set V=V(G) of vertices (or points or nodes)
(ii) A set E=E(G) of edges; where each edge corresponds to a pair of
vertices.
Lecture 01
Directed Graph/digraph
A directed graph is graph, i.e., a set of objects (called vertices or nodes) that
are connected together, where all the edges are directed from one vertex to
another. A directed graph is sometimes called a digraph or a directed network.
• In-degree of vertex v: the number of
edges entering v.
• out-degree of vertex v: the number of
edges leaving v.
• Total degree of vertex v: the sum of in
and out degree
• v is adjacent to u if there is an edge (v, u)
Lecture 01
Undirected Graph/digraph
An undirected graph is graph, i.e., a set of objects (called vertices or nodes) that are
connected together, where all the edges are bidirectional. An undirected graph is
sometimes called an undirected network. In contrast, a graph where the edges point in
a direction is called a directed graph.
• degree of vertex v: the number of edges
incident on v.
• v is adjacent to u and u is adjacent to v if
there is an edge (u, v)
Lecture 01
Simple Graph
A simple graph is a graph that does not have any loops or parallel edges. In a
simple
graph, an edge with endpoints v and w is denoted {v, w }.
complete graph
A complete graph on n vertices, denoted Kn, is a simple graph with n
vertices and exactly one edge connecting each pair of distinct vertices.
Lecture 01
The Concept of Degree
Let G be a graph and v a vertex of G. The degree of v, denoted deg (v),
equals the
number of edges that are incident on v, with an edge that is a loop counted
twice.
The total degree of G is the sum of the degrees of all the vertices of G.
Lecture 01
Graph Representations
In graph theory, a graph representation is a technique to store graph into the
memory of computer.
To represent a graph, we just need the set of vertices, and for each vertex the
neighbors of the vertex (vertices which is directly connected to it by an edge). If it is
a weighted graph, then the weight will be associated with each edge.
There are different ways to optimally represent a graph, depending on the density of
its edges, type of operations to be performed and ease of use.
Lecture 01
1. Adjacency Matrix
•Adjacency matrix is a sequential representation.
•It is used to represent which nodes are adjacent to each other. i.e. is there any edge
connecting nodes to a graph.
•In this representation, we have to construct a nXn matrix A. If there is any edge from a
vertex i to vertex j, then the corresponding element of A, ai,j = 1, otherwise ai,j= 0.
•If there is any weighted graph then instead of 1s and 0s, we can store the weight of the
edge.
Lecture 01
Undirected graph representation
Directed graph representation
Undirected weighted graph representation ????
Lecture 01
Pros: Representation is easier to implement and follow.
Cons: It takes a lot of space and time to visit all the neighbors of a
vertex, we have to traverse all the vertices in the graph, which takes
quite some time.
Lecture 01
2. Incidence Matrix
In Incidence matrix representation, graph can be represented using a matrix of size:
Total number of vertices by total number of edges.
It means if a graph has 4 vertices and 6 edges, then it can be represented using a matrix
of 4X6 class. In this matrix, columns represent edges and rows represent vertices.
This matrix is filled with either 0 or 1 or -1. Where,
0 is used to represent row edge which is not connected to column vertex.
1 is used to represent row edge which is connected as outgoing edge to column vertex.
-1 is used to represent row edge which is connected as incoming edge to column vertex.
Lecture 01
Lecture 01
3. Adjacency List
Adjacency list is a linked representation.
In this representation, for each vertex in the graph, we maintain the list of its neighbors.
It means, every vertex of the graph contains list of its adjacent vertices.
We have an array of vertices which is indexed by the vertex number and for each vertex
v, the corresponding array element points to a singly linked list of neighbors of v.
Lecture 01
Lecture 01
Lecture 01
Pros:
•Adjacency list saves lot of space.
•We can easily insert or delete as we use linked list.
•Such kind of representation is easy to follow and clearly shows the adjacent
nodes of node.
Cons:
•The adjacency list allows testing whether two vertices are adjacent to each other
but it is slower to support this operation.
Lecture 01
Assignment
1. Ten people are seated around a circular table. Each person shakes hands with
everyone at the table except the person sitting directly across the table. Draw a
graph that models this situation.
2. Six fraternity brothers (Adam, Bert, Chuck, Doug, Ernie, and Filthy Frank) need to
pair off as roommates for the upcoming school year. Each person has compiled a list
of the people with whom he would be willing to share a room.
Adam’s list: Doug Bert’s list: Adam, Ernie
Chuck’s list: Doug, Ernie Doug’s list: Chuck
Ernie’s list: Ernie Frank’s list: Adam, Bert
Draw a digraph that models this situation.