Professional Documents
Culture Documents
13 de noviembre de 2019
Graph theory
Definition 1 Graph.
A function γ that maps each edge to a subset {v,w}, where v y w are vertices
(they could be the same vertex).
An edge a that connects v and w is denoted by γ(a) = {v, w}. In that case, the
vertices v and w are the end-nodes of a.
1
2 Graph theory
1 2
4 3
1 2
3 4
C
E
D
F
1 6
In Figure 1.4 the sequence a, b, c, d, c is not a path, since edge given by d and c are
chosen twice.
Definition 11 Connected graph. A graph where there exist a path from a vertex to
any other.
Definition 13 Subgraph of graph components are the parts that conform a discon-
nected graph.
Example 1.1.5 Graphs 1.1 and 1.2 are connected graphs (individually). Graph 1.3
is disconnected since vertex E has no edges as a path toward the rest of the vertices.
Grapf of Figure 1.3 has two components, the former given by vertices A, B, C, D, F
and the other conformed by vertex E.
Example 1.1.6 Figure 1.6 shows discret graph: D1 , D2 , D3 , D4 and D5 with one,
two, three, four, and five vertices respectively.
Note:
All complete graph Kn is regular and each vertex has degree equal to n − 1.
All discrete graph is regular since each vertex has zero degree.
Figure 1.7 illustrate complete graphs K3 , K4 , and K5 .
K3 K4 K5 K6
L2 L3 L4 L5
D
B C
1 5
Definition 18 An Eulerian path is a path in graph G that includes each edge just
once.
e
c d
f g
1. If a graph G has at least one vertex with odd degree, then there is no an Eulerian
circui in G.
2. If G is a connected graph and all vertices has even degree, then there exist an
Eulerian circuit in G.
1. If a graph G has more that two vertices with even degree, then there is no an
Eulerian path G.
2. If G is connected grapg and it has two vertices exacly with odd degree, then
there exist an Eulerian path in G. Moreover, any Eulerian path must start in a
vertex with odd degree and end in the second with odd degree.
c e
Example 1.1.10 Path a, b, c, d, e is a hamiltonian path, since it uses each vertex just
once.
Note that all complete graph Kn has hamiltonian circuits.
Example 1.1.11 When starting in any vertex, it is possible to visit all the vertex
sequentially in some desired order. For K3 it is possible to verify the next hamiltonian
trajectories as is shown in Figure 1.13: {a, b, c}, {a, c, b}, {b, a, c}, {b, c, a}, {c, a, b},
{c, b, a}.
Example 1.1.12 It is possible to verify all 4! = 16 hamiltonian trajectories according
to graph K4 (right side in Figure 1.13) that corresponds to pertumations of 4 vertices:
{1, 2, 3, 4}, {1, 2, 4, 3}, {1, 3, 2, 4}, {1, 3, 4, 2}, {2, 1, 3, 4}, {2, 1, 4, 3},
{2, 4, 3, 1}, {2, 4, 1, 3}, {3, 1, 2, 4}, {3, 1, 4, 2}, {3, 2, 4, 1}, {3, 2, 1, 4},
{4, 1, 2, 3}, {4, 1, 3, 2}, {4, 2, 1, 3}, {4, 2, 3, 1}.
Let G a connected graph with n vértices, n ≥ 2 without loops and with no multiple
vertices.
Theorem 1.1.3 A graph G with n vértices has a hamiltoniano circuit if for any pair
of non-adjacents vertices u and v in G, the degree of u plus the degree of v is greater
than or equal to n.
b
c 4 3
K3 K4
Corollary. A graph G has at least one hamiltonian circuit if each vertex has a
degree greater than or equal to n2 .
Theorem 1.1.4 let m the number of edges in G and let n the number of vertices,
then G has a hamiltonian circuit if m ≥ 12 (n2 − 3n + 6).
Example 1.1.13 Para una gráfica completa K4 cada vértice tiene grado 3, enton-
ces según el Teorema 1.1.3 para cualquier par de vértices no adyacentes la suma de
sus grados es 6, que es mayor que n = 4, por lo tanto existe al menos un circuito
hamiltoniano.
Example 1.1.14 Los recı́procos de los Teoremas 1.1.3 y 1.1.4 no son válidos, es decir
las condiciones dadas son suficientes pero no necesarias, para la conclusión. Considere
la gráfica de la figura 1.14. El número de vértices es n = 8, cada vértice tiene grado
igual a 2, y para cualquier par de vértices no adyacentes la suma de sus grados es
4. El número total de aristas también es 8. Por lo tanto, las premisas de los Teore-
mas 1.1.3 y 1.1.4 no son satisfechas pero existen circuitos hamiltonianos para la gráfica
de la figura 1.14, por ejemplo: {A, B, C, D, E, F, G, H}, {B, C, D, E, F, G, H, A}, . . . ,
{H, A, B, C, D, E, F, G}.
1.2. Exercices
Exercise 1.2.1 Definir los elementos la gráfica G = (V, E, γ} asociada con la figu-
ra 1.3.
H B
G C
F D
$ swipl
?- [graph].
true.
?- path(a,g,[a],Path).
Path = [a, b, d, e, g] ;
Path = [a, b, d, f, g] ;
Path = [a, b, d, g] ;
Path = [a, c, d, e, g] ;
Path = [a, c, d, f, g] ;
Path = [a, c, d, g] ;
Path = [a, d, e, g] ;
Path = [a, d, f, g] ;
Path = [a, d, g] ;
false.
?-
Motivación.
Ası́ como se establecen relaciones entre los individuos en la sociedad, es posible definir
matemáticamente relaciones entre los elementos de dos o más conjuntos. La represen-
tación de objetos del mundo real como elementos de conjuntos matemáticos permite
darle solución a problemas asociados al aplicarles diferente operadores y explorar sus
propiedades. Ejemplo de ello son la identificación de clientes que suelen comprar cierto
tipo de productos (libros, pelı́culas, etc.) o servicios (usuarios de diferentes estaciones
de radio, proveedores de internet, etc.) y con ello realizar predicciones y elecciones
de nuevos productos o servicios. Por lo tanto, conviene conocer las bondades que los
conceptos de árboles nos brindan. Comencémos con este tema.
Definition 23 Relación binaria.
Dados dos conjuntos A y B, una relación binaria es un subconjunto de A × B.
Una forma usual para expresar relaciones entre elementos de dos conjuntos A y B es
mediante un par ordenado (a, b). También suele usarse la notación a R b para denotar
que existe una relación entre a ∈ A y b ∈ B.
Example 1.3.1 Dé una representación visual de la relación R entre el conjunto de
personas A y el conjunto de sus colores favoritos B donde A = {Alberto, Benito, Carlos}, B =
{azul, blanco} y R = {(Alberto, azul), (Alberto, blanco), (Benito, azul), (Carlos, blanco)}.
15
16 Árboles
Definition 24 Árbol.
Un árbol T es una relación sobre un conjunto A de vértices, tal que existe un vértice
raı́z vr con una única trayectoria hacia cualquier otro vértice en A, pero no existe una
trayectoria de vr a vr .
La figura 1.17 muestra una representación visual del árbol del ejemplo 1.3.2.
v2 v5 v6
v1 v3 v8 v7
v9 v10
Exercise 1.3.4 ¿Cuál es el nivel de los vértices v9 y v10 en el árbol de la figura 1.17?
Solution 1.3.5 Las hojas no tienen trayectorias que inicien en esos vértices, por lo
tanto no tienen hijos.
Solution 1.3.6 Sea v0 el vértice raı́z con dos hijos y sus correspondientes aristas
que tienen por destino a los vértices v1 y v2 . Cada vértice v1 y v2 tiene a su vez dos
vértices v3 , v4 y v5 , v6 respectivamente. La trayectoria de v0 a cualquiera de los vértices
v3 , v4 , v5 o v6 es 2 por lo tanto el árbol se describe mediante A = {0, 1, 2, 3, 4, 5, 6} y
T = {(v0 , v1 ), (v0 , v2 ), (v1 , v3 ), (v1 , v4 ), (v2 , v5 ), (v2 , v6 )}.
Definition 31 Subárbol.
Dado un vértice vs ∈ A, un subárbol es el árbol que se obtiene al considerar los vértices
hijos de vs y las aristas que los conectan. El vértice vs es la nueva raı́z del subárbol.
* 4
2 +
1 3
Por lo tanto la salida del recorrido del árbol de la figura 1.18 en preorden es:
− ∗ 2 + 1 3 4.
asterisco, IMPRIME *
14. se continúa con el punto 3 donde vR es el subárbol de la derecha tiene por raı́z al
número 4, IMPRIME 4
15. VC : el vértice central tiene el signo menos, IMPRIME -
Por lo tanto la salida del recorrido del árbol de la figura 1.18 en posorden es:
2 1 3 + ∗ 4 −.
Motivation. The automata inputs can represent events that change the current
state of the automata, such as events that change our mood.
δ a transition function
q0 ∈ Q initial state
25
26 Finite Deterministic Automata
Definition 36 Formal Language of an FDA. The set with all the strings that are
accepted by the FDA.
Recursive functions are conformed by two steps: Base step and recursive step.
Base step. Base case applyies to process an empty string where δ̂(q0 , ) =
δ(q0 , ) = q0
Example 1.4.1 Regular expression: 1∗ 00∗ 1(0|1)∗ represents all strings accepted by
automata of Figure 1.19
Q = {q0 , q2 , q1 } = {q0 , q1 , q2 } given that sets have no ordered elements (is not
relevant).
q0 ∈ Q initial state.
F = {q1 }
S = s1 s2 . . . sn−1 sn
w = s1 s2 . . . sn−1
S = wsn
Then
δ̂(q, wsn ) = δ(δ̂(q, w), sn )
Example 1.4.3 Process the string S = 100101 with automata given in Figure 1.19.
δ̂(q0 , ) := δ(q0 , ) = q0
Alternatively:
δ̂(q0 , 1) = δ(q0 , 1) = q0
δ a transition function: P Q × 7→ P Q
q0 ∈ Q initial state
[
δ̂(q, ws) = δ(δ̂(q, w), s)
[
δ̂(q0 , 00101) = δ(δ̂(q0 , 0010), 1) = δ({q0 , q1 }, 1) = δ(q0 , 1)∪δ(q1 , 1) = {q0 }∪{q2 } = {q0 , q2 }
[ [
δ̂(q0 , 0010) = δ(δ̂(q0 , 001), 0) = δ({q0 , q2 }, 0) = δ(q0 , 0)∪δ(q2 , 0) = {q0 , q1 }∪{} = {q0 , q1 }
[ [
δ̂(q0 , 001) = δ(δ̂(q0 , 00), 1) = δ({q0 , q1 }, 1) = δ(q0 , 1)∪δ(q1 , 1) = {q0 }∪{q2 } = {q0 , q2 }
[ [
δ̂(q0 , 00), 0) = δ(δ̂(q0 , 0), 0) = δ({q0 , q1 }, 0) = δ(q0 , 0) ∪ δ(q1 , 0) = {q0 , q1 } ∪ {}
[
δ̂(q0 , 0) = δ(q0 , 0) = {q0 } ∪ {q1 } = {q0 , q1 }
Reflexion.
How do you imagine Figure 1.20 could be adapted to illustrate a non-deterministic
FDA?
in this case we process the String S = 00101 with the NFDA approach followed by
the deterministic approach.
Non-deterministic approach Instead of applying the extended functions, it is
illustrated a expansion-tree where the automata if Figure 1.23 explores several states
simultaneously to process the string S = 00101 (see Figure 1.23).
Deterministic approach. With the AFD given in Figure 1.22 (equivalent to the
NFDA of Figure 1.22:
NFDA requires many CPUS whereas FDA requires a lot of memory space,
but they are able to process the same language (equivalence).
q0 ∈ Q initial state
Example 1.4.5
δ̂(q, ws) = δ(C{δ̂(q, w)}, s)
δ̂(q0 , 1.2) = δ(C{δ̂(q0 , 1.2)}, ) = δ(C{q3 }, ) = δ({q3 , q5 }, ) = δ(q3 , )∪δ(q5 , ) = {q5 }∪{} = {q5 }
Example 1.4.6 Figure 1.25 shows two equivalent automata, FDA and NFDA.
Figura 1.25: Automata equivalence, AFD vs AFND. See Brookshear’s book p.47
p current state
q new state
1.5. Grammars
Definition 44 Grammar. 4-tuple G = {V, T, P, S} where:
2. Right side has a terminal followed by a single variable, a single terminal or the
empty set.
P 1. Z → yX
P 2. Z → x
P 3. W → 1
P 4. S → xX
P 5. X → yY
P 6. Y → xX
P 7. Y → {}
Theorem 1.5.1 Regular languajes are acepted by AFD and there exist a regular
grammar that accept the same language.
Figura 1.27: Automata equivalence, regular grammar vs AFD. See Brookshear’s book
p.54
Figure 1.27 illustrates a regular grammar such that its language is accepted by an
automata with states Q = {S, X, Y } that corresponds to the set of variables V of the
regular grammar.
Theorem 1.5.2 A regular language is accepted by an AFD and there exist a regu-
lar grammar that accepts the same language. L(AFD) = L(G) = Regular language
expressed as a regular expression.
El término independiente del contexto refleja que, como el lado izquierdo de cada
producción únicamente tiene una variable (no está rodeada de nada), ası́ que la regla
puede aplicarse sin importar el contexto donde se encuentre dicha variable.
Theorem 1.5.3 Para cada gramática independiente del contexto GIC, existe un
autómata de pila PDA tal que L(GIC) = L(PDA).
Gramática dependiente del contexto. Una regla como xN y → xzy tiene una variable
rodeada de x por la izquierda además de y por la derecha, ası́ que sólo se puede aplicar
cuando N tenga x − y a sus lados, lo cual lo hace dependiente del contexto.
Example 1.5.2 GIC que genera cadenas de la forma zan zan bm zbm z:
S → zM N z
M → aM a
M →z
N → bN b
N →z
La cadena zazabzbz cumple con esta patrón, y la Figura 1.28 ilustra el árbol de pro-
ducciones (derivación) que la generan.
Figura 1.29:
Figura 1.30:
A → Ac
A→w
A→X
X→z