- 145 Views
- Uploaded on
- Presentation posted in: General

GRAPHS & COMBINATORICS

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

GRAPHS & COMBINATORICS

Antonio Hervás Jorge

ahervas@mat.upv.es

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

- Basic components
- . Connectivity and conected components
- Connectivity in non-directed graphs

- Graph representations
- Adjacency matrix
- Incidence matrix
- Accesibility matrix
- Adjacency lists

- Search methods in graphs
- Breadth First Search (BFS)
- Depth First Search (DFS)

- The problem of the shortest path with just one origin
- Minimum paths joining all the nodes of a graph

The problem of the shortest paths

A.H.J.-2.003

Definition.-

Let G =(V,E) be a non-directed graph. We shall call chain from node v1 to node vk , the series of nodes and edges:

P = v1, a1, v2 , a2 , ..., vk , ak , vk+1

so that For all j, 1 ≤ j ≤ k , aj = ( vj, vj+1 )

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

All edges being different Simple chain

Whenever v1 = v k+1Closed chain

All nodes being different P path

Whenever a path, v1 = v k+1P cycle

Number of edges of a path lenght

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

Definition.-

Let G = (V,E) be a directed graph . We shall call directed semi-path from node v1 to node vk , the series of nodes and edges:

P = v1, a1, v2 , a2 , ..., vk , ak , vk+1

so that For all j, 1 ≤ j ≤ k ,aj = < vj , vj+1 > o aj = < v j+1 , vj >

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

SEMI-CYCLESEMI DIRECTED PATH

A.H.J.-2.003

Connectivity and connected components

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

Connectivity in non-directed graphs

- Properties of the connectivity relation:
- A node is connected to itself by means of a path whose length is zero.
- Whenever there is a path from u to v, there will also exist a path from v to u.
- Whenever there is a path from uto v and another from v to w, then u and w nodes are connected

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

CONNECTIVITY relation defined on a set of nodes of a non-directed graph

VERIFIES THE PROPERTIES:

Reflexive Symetric Transitive

→Binary Relation of Equivalence

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

- [1]= {1,3,5} =[3]=[5]
- [2]={2,4,6}

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

Example.- 1 3

2 Graph 2-connected

5 4 made up of:

2 connected components

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

How can we define the best directed connectivity?

How can we define the conectivuty in directed graphs?

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

Theorem.-

Let G be a non-directed and connected.

G bypartite G has no odd length

cycles

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

THEOREM

G non-directed graphG has:

connected non-triviala zero degree node

a cycle

or both

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

THEOREM

Let G =( V, E) be a non-directed connected graph and C

a cycle in G.

e edge from CG - {e } connected

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

THEOREM

G non-directed connected graph

with |V| 2

Nº edges |V| - 1

from G

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

THEOREM

G directed strongly connected

graph with |V| 2

nº edges |V|

from G

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

THEOREM

V set of nodes

non-directed connected graph with

|V | - 1 edges

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

TEOREMA

V set of nodes

directed strongly connected graph with |V| edges

A.H.J.-2.003

Graph representation.

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

The existence of some edges

between the nodes enables for

a double representation of the

graph

The connectivity among

nodes results in

Adjacence Matrix.

Incidence Matrix..

Accesibility Matrix.

Accesibility Matrix.

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

Definition.-

Let G = (V,E) be a graph.

We shall say that vj is whithin reach from vi , if there is

a path (either directed or not) fromvito vj .

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

Definition.-

We define the Accesibility matrix of a graph with

n nodes and denote it by R = [r(i,j)] n n as

r(i,j) =

{

1, whenever vj is whithin reach from vi

0, otherwise.

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

We shall call R(vi) the nodes within reach from vi.

We obtain these nodes from using the function

That is:

R(vi) = whithin reach from (vi) =

= {vi} (vi) . . . n (vi)

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

Definition.-

We shall define the Access Matrix as the transposed

to the accesibility matrix. It is denoted by Q = [q(i,j)] n n

and defined as:

q(i,j) =

{

1, whenever vi it is within reach from vj

0,otherwise.

If the graph The accesibility matrix

is a non-directed one and the access matrix

coincide ( it is symetric)

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

Graph Search Methods

- Breadth First Search (BFS)
- Depth First Search (DFS)

A.H.J.-2.003

Algorithm (BFS)

BFS (v) procedure

/* se aplica sobre un grafo G de n vértices */

global G, n, ALCANZADO (1:n);

cola COLA;

x v;

ALCANZADO (v) 1;

inicializar la cola a vacío;

bucle

para todos los vértices w no adyacentes desde x hacer

si ALCANZADO (w) = 0

entonces

ALCANZADO (w) 1

añadir w a COLA

si COLA está vacia

entonces return

borrar el vértice x de COLA

fin del bucle

fin BFS

A.H.J.-2.003

Graphs & Combinatorics.

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

Results from applying

the BFS Algorithm

on any G graph:

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

We shall use the algorithm

to find the connected components

of an

unconnected non-directed graph.

Results:

If the node i is whithin reach from the first node of the path, then:

ALCANZADO (i) = 1

In non-directed graphs, if the node ALCANZADO has only got 1 numbers , then:

CONNECTED Graph

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

Algorithm (DFS)

DFS (v) procedure

/* se aplica sobre un grafo G de n vértices */

global G, n, ALCANZADO (1:n);

integer v, w;

ALCANZADO (v) 1;

para todos los vértices w (no alcanzados) adyacentes desde x hacer

call DFS (w)

fin del para

fin BFS

A.H.J.-2.003

The problem of the shortest paths.

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

The problem of finding the shortest path/s

from a x node

to another node

and/orto the rest of

the graph nodes

among each and every

one of the graph nodes.

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

The problem of the shortest paths with just one origin

G = (V,E) a directed graph.

C = [ C(p,q) ]n n the weight matrix of the graph G.

s Vthe origin node.

Find the cost of the shortest path from the origin node sto the rest of the nodes inV.

(The cost of the path is the result of adding up the weights of the path arcs)

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

Wheights of the graph edges

POSITIVE

NEGATIVE

BELLMAN-FORD

Algorithm.

DIJKSTRA

Algorithm.

A.H.J.-2.003

Departamento de Matemática Aplicada

DIJKSTRA Algorithm.

- The weights C(p,q) from all edges must be positive
- Whenever an edges is not on the graph we labell it with
weight +

- Every node will be labelled as l(xi).
- - It will represent a higher level of the length of the
- shortest path from the initial node to the node xi ..
- - It will be variable in principle, but in every iteration
- one will be fixed.
- In every iteration the node labells disminish.
- ( As the nodes are reached from the origin node)
- The algorith finishes when the labell of the searched node
- is fixed( or all labells are fixed)

A.H.J.-2.003

Departamento de Matemática Aplicada

DIJKSTRA Algorithm.

[Step1] Let s be the origin node, we labell it as

l(s) = 0.

l(xi) = + xi V /* variable */

Let P = s be.

[Step 2] For all xi(P) with variable labell,

update the labells:

l(xi) = min [ l(xi) , l(P) + C(P, xi) ]

[Step 3] Let xi = min [ l(xj) ] , xj with variable labell.

[Step 4] Mark the labell from xi as fix and take

P = xi .

*

*

*

A.H.J.-2.003

Departamento de Matemática Aplicada

[Step 5]

(1) if we only wish to know the shortest path from s to t.

if P = t

then

l(P) is the length of the shortest path searched

STOP.

otherwise go to STEP2.

(2) if we only wish to know the shortest paths

from s to the rest of the nodes.

If all nodes have a fix labell

then tese labells indicate the length

of the shortest paths

STOP.

Otherwise go to step 2.

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

Theorem.

The DIJKSTRA Algorithm gives the The shortest paths

from a v node to the rest of the nodes in a connected graph

with a positive weight matrix.

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

Algoritmo de BELLMAN-FORD.

It gives the shortest path among two or more nodes in a connected graphwheighted with the general weight matrix (either positive or negative).

There must not exist any cycles with negative total weight

Nodes will be labelled as lk(x).

- It represents the shortest path from node

s to node x having k or less edges.

- They remain variable until the last iteration.

- At the end of k iteration we will calculate the labell k + 1

The algorithm will finish as soon as it calculates paths of n - 1 length ( or the largest if they are shorter ).

A.H.J.-2.003

Departamento de Matemática Aplicada

BELLMAN-FORD Algorithm.

[Step 1] Inicialización.

S = (s);

k = 1;

and labells:

l1 (s) = 0;

for all xi (s) : lk (xi) = C(s, xi)

for the rest of the nodes lk (xi) =

[Step 2] For all xi (S) update the labells:

lk+1 (xi) = min [ lk (xi) , minx j Ti { lk (xj) + C(xj,xi) } ]

Ti = -1 (xi) S

lk+1 (xi) = lk (xi) for xi(S) 1

A.H.J.-2.003

Departamento de Matemática Aplicada

[Step 3]Ending test.

a) If k n-1 and xi, lk+1(xi) = lk(xi) STOP.

We have obtained the length of the shortest paths

given by the current labells.

b) if k < n-1 and there is any xi , lk+1(xi) lk(xi) STEP4.

c) If k = n-1 and there is any xi , lk+1 lk(xi)

there is NO SOLUTION.

STOP.

[Step 4] S = { xi / lk+1 (xi) lk (xi) }

S has the nodes whose shortest paths is of

k+1 cardinality.

[Step 5]k = k+1; go to STEP 2.

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

Minimum path among all the nodes of a graph.

FLOYD-WARSHALL Algorithm.

It acts directly on the weight matrix, but does not labell the nodes.

It calculates the length of the shortest paths amongall the nodes of a graph.

It finds the cycles with negative weight (as far as they exist).

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

Weight matrix of the graph.

it is updated in every iteration.

C = (cij)

Weight matrix of a graph where:

- the nodes are those of the original graph

- The edges are the shortest paths

with k or less edges in the initial graph.

Ck

A.H.J.-2.003

Graphs & Combinatorics.

ESTRUCTURAS MATEMÁTICAS PARA LA INFORMÁTICA II

At the begining, in the diagonal of the C matrix there

are only zeros.

If any value of the diagonal turns out to be negative

Cycle of total weight is negative.

There is no solution.

Otherwiseafter n iterations we will obtain the matrix

with the length of the shortest paths.

A.H.J.-2.003

Departamento de Matemática Aplicada

FLOYD-WARSHALL Algorithm.

[Step 1]k = 0

[Step 2]k = k+1

[Step 3]i k / cik

j k / ckj

[Step 4]a) If cii < 0 STOP,negative weights circuit.

b)If i, cii0 ^ k = nSTOP.

[cij] nn represents the length of the shortest paths of xi a xj

c) cii > 0 , i, k < n go to STEP 2.

}

cij = min { cij, cik + ckj }

A.H.J.-2.003