0% found this document useful (0 votes)
5 views37 pages

Graphs Theory

The document provides an extensive overview of graph theory, including definitions, classifications, and properties of graphs. It covers concepts such as vertices, edges, graph representations, and various types of graphs like Eulerian and Hamiltonian graphs. Additionally, it discusses graph matrices, spanning trees, and algorithms for finding minimum spanning trees, along with exercises for practical application.

Uploaded by

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

Graphs Theory

The document provides an extensive overview of graph theory, including definitions, classifications, and properties of graphs. It covers concepts such as vertices, edges, graph representations, and various types of graphs like Eulerian and Hamiltonian graphs. Additionally, it discusses graph matrices, spanning trees, and algorithms for finding minimum spanning trees, along with exercises for practical application.

Uploaded by

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

Badji Mokhtar Annaba University

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).

Think of it as a network of connected points.

Examples:

Social network: People as vertices, friendships as edges.


Transport network: Cities as vertices, roads as edges.
2.Mathematical Definition of a Graph
A finite graph G=(V,E) is defined by:
A finite set V={v1,v2,...,vn} , whose elements are called vertices (or nodes).
A finite set E={e1,e2,...,em} , whose elements are called edges (or links).

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:

Incident Edges and Vertices: An edge is incident to the vertices it connects.


Example: If edge e connects vertices A and B, then e is incident with A and B.

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.

2.Multigraph: Allows multiple edges between the same pair of vertices.

3.Pseudograph: Allows both multiple edges and loops.


4.Directed vs. Undirected:

Directed Graph (Digraph): Edges have a direction, represented by arrows.


Undirected Graph: Edges have no specific direction, representing a mutual relationship.

5.Weighted Graph: Edges carry a "weight" or value, representing attributes like distance, cost, or capacity.

6.Planar Graph: Can be drawn on a plane without edges crossing.


7.Connected Graph:
A graph is considered connected if, from any given vertex, it's possible to reach all other vertices by
following the edges.
In other words, there exists a path between any two vertices in a connected graph.

Disconnected Graphs and Connected Components:


If a graph is not connected, it is called disconnected.
Disconnected graphs can be broken down into connected components. Each connected component is
a subgraph in which any two vertices are connected by paths, but no vertex is connected to vertices
outside the component.

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.

A.Vertex-Edge Incidence Matrix:


This matrix shows the relationship between vertices (rows) and edges (columns).

Undirected grap

Directed grap
VB.ertex-Vertex Adjacency Matrix:
This matrix shows which vertices are adjacent.
Adjacency Matrix for undirected graph

Adjacency Matrix for directed graph


Here’s a quick recap of the main concepts covered in last class:

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

Adjacent Vertices: Two vertices connected by an edge.

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).

Incident Edges: An edge is incident with the vertices it connects.


5. Graph Classifications

Simple Graph: No loops or multiple edges.


Multigraph: Allows multiple edges between vertices.
Pseudograph: Allows loops and multiple edges.
Weighted Graph: Edges have weights or values.
Planar Graph: Can be drawn without edge crossings.
Connected Graph: Any vertex is reachable from any other vertex.
Disconnected Graph: Can be broken into connected components.
Complete Graph: Every vertex is directly connected to every other vertex.
Bipartite Graph: Vertices can be split into two sets, where edges only connect vertices in one set to those
in the other.

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

Let G=(V,E)be a graph. The graph G′=(V,E′) is a partial graph of G if E′ is included in E.


In other words, G′ is obtained by removing one or more edges from graph G.

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.

A partial graph of a subgraph is a


partial subgraph of G.
A clique is a complete subgraph
of G. In the graph G , the
subgraph K=(V,E), with V={1,3,4}
Graph G Partial graph of G Subgraph of G
and E={{1,3},{1,4},{3,4}} is a clique.
6.Vocabulary related to connectivity
A chain in G is a sequence alternating between vertices and edges, starting and ending with a vertex, such
that each edge is framed by its endpoints.

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)

A chain is not changed by reversing the order of the elements in the


corresponding sequence. Thus, the chains (v1,e3,v3,e4,v4)and
(v4,e4,v3,e3,v1) are identical.
The distance between two vertices is defined as the length of the shortest chain connecting them.
The diameter of a graph is the longest distance between any two vertices.
A chain is elementary if each vertex appears at most once in it.
A chain is simple if each edge appears at most once. (v1,e1,v2,e2,v3) is a simple and elementary chain.
A chain whose starting and ending vertices are the same is called a closed chain.
(v4,e4,v3,e5,v5,e5,v3,e4,v4) is a closed chain.
A simple closed chain is called a cycle. the chain (v1,e1,v2,e2,v3,e3,v1) is a cycle.

Q:What are the graphs with diameter 1?


Eulerian Graphs
An Eulerian cycle in a graph G is a loop that travels through each edge exactly once, ending where it
started. A graph with an Eulerian cycle is called Eulerian.
For a graph to be Eulerian, each vertex must have an even degree.

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.

A graph with a vertex of degree 1 (only one edge) cannot be Hamiltonian.

Hamiltonian path
Eulerian Graphs: Hamiltonian Graphs:
Focus on edges. Focus on vertices.
Exercise: Exploring Eulerian and Hamiltonian Properties

Consider a graph G(S,A) where:


S={ A,B,C,D, E } and A={(A,B), (A,C),(B,C),(B,D),(C,D),(C,E), (D,E),(D,A),(E,A)}.

Draw the Graph G

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.

Maximum Spanning Tree:


A maximum spanning tree is similar to an MST but aims to maximize the total edge weight instead of
minimizing it.
It still connects all vertices with n−1 edges but with the heaviest edges, ensuring a maximum weight sum.
Kruskal's Algorithm (for Minimum Spanning Tree):

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

Total MST Cost: 3+4+5+6=18 €


Pipes Selected: C−E,C−D,B−C,A−C
2.Minimum Spanning Tree (MST) –
Minimize Cost 3.Maximum Spanning Tree (MaxST)
– Maximize Flow Capacity
Total MaxST Flow Capacity: 12+10+8+7=37 L/h
Pipes Selected: A−B,B−D,A−C,C−D

Asma Chebli

You might also like