Graphs Theory
Graphs Theory
Faculty of Technology
GRAPHS
THEORIE
Lecturer: Asma CHEBLI
2024-2025
1.Intuitive Definition of a Graph
A graph is a set of points (called vertices or nodes) connected by lines (called edges).
Examples:
2.1Graphical Representation
Graphs are named after their visual representation.
Each vertice of G is represented by a distinct point on a plane.
Edges are represented by lines connecting the points (vertices) at each end.
A graph can have many possible representations.
Edges don’t need to be straight lines , they can be curved or arranged in different ways
A graph is planar if it can be drawn without any edges crossing each other.
A planar representation
of G
A non-planar representation
of the graph G (intersecting edges)
3.Order, Orientation, and Multiplicity of a Graph
A.Order of a Graph:
The order of a graph is the number of vertices (nodes) it contains.
Example: A graph with 5 vertices has an order of 5.
B.Orientation:
Undirected Graph: Edges have no specific direction; the connection is bidirectional.
Vertices A, B, C, and D connected without a specific direction
Directed Graph (or Digraph): Each edge has a direction (represented by an arrow) indicating a one-way
connection between vertices.
A→B, B→C, C→D with arrows showing direction
C.Multiplicity:
If a graph contains multiple edges between the same pair of vertices, it is called a multigraph.
In a multigraph, the same two vertices can have more than one edge connecting them.
Two or more edges between vertices a and b.
Graph has an order of 5
4.Relationships Between Graph Elements
A.Relations Between Vertices
In graph theory, vertices (or nodes) are connected by edges (or links), and relationships between
vertices define how they interact or connect in the structure of a graph.
Adjacent Vertices:
Two vertices are adjacent if there is a direct edge between them.
Example: If vertices A and B are connected by an edge e, then Aand B are adjacent.
Adjacency indicates a close or direct relationship, often used to model connections, proximity, or direct
links in a network.
Degree of a Vertex:
The degree of a vertex is the count of edges connected to it.
In an undirected graph, the degree is the total number of edges touching the vertex.
In a directed graph, we differentiate:
In-degree: The number of edges pointing into the vertex.
Out-degree: The number of edges pointing out from the vertex.
B.Relations Between Edges and Vertices:
Loops: An edge that connects a vertex to itself, increasing the vertex's degree by two in an undirected
graph.
Loop
C.Graph classification
Graph classification refers to the categorization of graphs based on their structural characteristics and
properties. This helps in identifying the types of problems they can represent and the mathematical
techniques we can use to analyze them.
1.Simple Graph: No loops (edges connecting a vertex to itself) and no multiple edges between any two
vertices.
5.Weighted Graph: Edges carry a "weight" or value, representing attributes like distance, cost, or capacity.
Example:
Consider the following graph :
The connected componentsof this graph are:
{1, 2, 3, 4}
{5, 6}
8.Complete Graph:
A graph is complete if every vertex is directly connected to every other vertex in the graph.
In a complete graph, there is an edge between each pair of distinct vertices.
9.Bipartite graph:
A graph is bipartite if its vertices can be divided into two disjoint sets, X and Y, where every edge in
the graph connects a vertex from X to a vertex from Y. No edges exist between vertices within the
same set.
Example: In the example provided:
Set X={1,3,5}
Set Y={2,4}
All edges link vertices in X to vertices in Y, or vice versa.
This structure is often used to represent relationships between two distinct types of entities, such as
professors and classes, or people and tasks.
5.Matrices Associated with a Graph
Graph matrices are mathematical representations that encode the relationships between vertices
and edges in a graph. They simplify analysis and calculations, especially for large graphs.
Undirected grap
Directed grap
VB.ertex-Vertex Adjacency Matrix:
This matrix shows which vertices are adjacent.
Adjacency Matrix for undirected graph
1. Definitions of a Graph
Intuitive Definition: A graph is a set of points (vertices) connected by lines (edges). Think of it as a
network showing relationships, like cities connected by roads or people by friendships.
Mathematical Definition: A graph G=(V,E) consists of:
V: Set of vertices (nodes)
E: Set of edges (connections between vertices)
2. Graph Representation
Visual Representation: Each vertex is a point on a plane, and edges connect these points. A graph is planar
if it can be drawn without edges crossing.
3. Order, Orientation, and Multiplicity
Order: Number of vertices in the graph.
Orientation:
Undirected Graph: Edges have no direction.
Directed Graph: Edges have a direction (arrows).
Multiplicity: A graph is a multigraph if it has multiple edges between the same pair of vertices.
4.Relationships in a Graph
Vertex Degree:
In undirected graphs: Degree is the number of edges touching the vertex.
In directed graphs: In-degree (incoming edges) and Out-degree (outgoing edges).
6. Graph Matrices
Vertex-Edge Incidence Matrix: Shows relationships between vertices (rows) and edges (columns).
Vertex-Vertex Adjacency Matrix: Indicates if two vertices are adjacent.
Example of Using a Graph to Solve a Problem
We have six train cars to sort. In the sorting station, the cars enter in the order 2, 5, 3, 6, 1, 4 and must exit
in ascending order.
Two cars i and j can be placed on the same track if and only if they enter in the order in which they need
to exit.
1. Draw a graph illustrating this situation, indicating what the vertices and edges of your graph
represent.
2. What will be the minimum number of tracks needed for sorting?
Partial Graph and Subgraph
For a subset of vertices A included in V, the subgraph of G induced by A is the graph G=(A,E(A)), where the
set of vertices is A and the set of edges E(A) is formed by all edges of G that have both endpoints in A.
In other words, G′ is obtained by removing one or more vertices from graph G, along with all edges
incident to those vertices.
We will say that the chain connects the first vertex of the sequence to the last vertex. Furthermore, we will
say that the chain has a length equal to the number of edges in the chain.
The graph below contains, among others, the chains (v1,e1,v2,e2,v3,e5,v5)) and (v4,e4,v3,e2,v2,e1,v1)
An Eulerian path (or chain) is a path that covers each edge exactly once but may end at a different vertex.
A graph with only Eulerian paths is called semi-Eulerian.
In simple terms, a graph is Eulerian (or semi-Eulerian) if you can trace it without lifting your pen or
retracing any edge.
Hamiltonian Graphs
A Hamiltonian cycle in a graph G is a cycle that visits each vertex exactly once and returns to the starting
point. A graph that has a Hamiltonian cycle is called Hamiltonian.
A Hamiltonian path (or chain) is a path that visits each vertex exactly once but does not necessarily return
to the starting vertex. A graph with only Hamiltonian paths is called semi-Hamiltonian.
Hamiltonian path
Eulerian Graphs: Hamiltonian Graphs:
Focus on edges. Focus on vertices.
Exercise: Exploring Eulerian and Hamiltonian Properties
Determine if G is Eulerian: Check if there exists an Eulerian cycle in the graph. Explain your reasoning
based on the degree of each vertex.
Determine if G is Hamiltonian: Check if there exists a Hamiltonian cycle in the graph. List a possible
path that covers each vertex exactly once and returns to the starting vertex, if it exists.
Additional Question: If you remove the edge between A and E, does G remain Eulerian or Hamiltonian?
Explain why or why not
Trees, Forests, and Arborescences
Definitions
Tree: A connected, acyclic graph(acyclic graph is a graph that has no cycles, meaning there are no paths
that start and end at the same node).
In a tree, there is a unique path between every pair of vertices and no cycles.
Forest: A disjoint set of trees, i.e., an acyclic graph that is not necessarily connected.
Arborescence: A directed tree with a root vertex, where each vertex (except the root) has exactly one
incoming edge (a predecessor).
Properties
A tree with n vertices has n−1n edges.
A tree is acyclic and connected.
In a tree, there is exactly one path between any two vertices.
A forest is an acyclic graph, but it may not be connected.
Spanning Tree
A spanning tree of a graph G is a subgraph of G that is a tree and includes all the vertices of G.
Minimum Spanning Tree (MST):
A minimum spanning tree is a tree that connects all the vertices of a graph with the minimum total edge
weight.
It has no cycles and exactly n−1 edges (for n vertices).
The goal is to minimize the sum of edge weights while keeping the graph connected.
Kruskal’s algorithm finds the minimum spanning tree using the following steps:
Sort all edges of the graph by weight (ascending order).
Start with an empty tree (set of edges).
Add edges to the tree one by one, ensuring no cyclesare formed.
Only add an edge if it connects two disjoint sets (use a disjoint-set data structure).
Repeat until the tree contains n−1 edges.
Example of Kruskal's Algorithm:
Given a graph with vertices A,B,C,D and edges with weights:
Edges: (A,B,1),(A,C,2),(B,C,3),(C,D,4)(A, B, 1), (A, C, 2), (B, C, 3), (C, D, 4)
1. Sort edges by weight: (A,B,1),(A,C,2),(B,C,3),(C,D,4)
2. Start with an empty tree.
3. Add edge (A,B,1) → no cycle.
4. Add edge (A,C,2)→ no cycle.
5. Add edge (B,C,3) → would form a cycle, skip it.
6. Add edge (C,D,4)) → no cycle.
The MST is formed by edges (A,B,1),(A,C,2),(C,D,4).
Exercise 1:
1. Given the graph G with vertices V={A,B,C,D}; and edges E={(A,B),(A,C),(B,D)}, determine whether G is a
tree, a forest, or an arborescence.
2. Given the graph A with vertices V={A,B,C,D,E} and edges E={(A,B),(B,C),(C,D),(D,E)}E = \{(A, B), (B, C), (C,
D), (D, E)\}, determine if it is an arborescence.
Exercise2:
Given the connected, weighted graph G , find the minimum spanning tree (MST) using Kruskal’s algorithm.
Graph G:
Vertices: V={A,B,C,D,E}
Edges:
E={(A,B,3),(A,C,1),(B,C,2),(C,D,4),(D,E,5),(B,E,6)}
Solution Exercice 01:
Graph 1: Graph 2:
It is a tree because if the following properties:
1. Connected: (All vertices can be reached from A). 1. Directed: (Assuming the pairs represent
2. No cycles directed edges).
3. Number of edges: 4−1=3 edges, which satisfies the tree condition 2. Rooted: (Root is A, and all nodes are reachable
from A).
It is not a forest 3. Acyclic: No cycles present.
1. A forest is a collection of disjoint trees. 4. Unique Path: Exactly one path from A to each
2. The graph is connected and a single tree, not disjoint. node.
It is an arborescence rooted at A.
It is not an arborescence
Requires directed edges and a root with a unique path to every node.
The graph is undirected.
Exercise: Water Distribution Network
A city wants to connect five water tanks (A, B, C, D, E) with pipes. Each pipe has a flow capacity (liters per hour) and a
cost for installation. The goal is to design an efficient water distribution system.
Pipe Capacities and Costs:
Tasks:
1. Draw a graph where the tanks are vertices and pipes are edges.
2. Label each edge with flow capacity and cost.
3. Using Kruskal’s algorithm, find the cheapest way to connect all tanks.
4. Show step-by-step selection of edges and calculate the total cost.
5. Using Kruskal’s algorithm but based on maximum flow capacity.
6. Calculate the total flow capacity and explain why this tree is useful for maximizing water flow.
Solution:
1.The Graph
Asma Chebli