Escolar Documentos
Profissional Documentos
Cultura Documentos
pt/md/grafos
Árvore
Teoremas de Árvores
Teorema 1
q = p-1q=p−1
Teorema 2
Definições
Árvore de cobertura
É uma árvore
É um subgrafo de gg que contém todos os vértices
Custo de árvore
Árvore Económica
Algoritmo de Trémaux
Exemplo
Algoritmo de Tarry
Exemplo
Teorema de Tarry
Iniciando um caminho num grafo conexo qualquer, e seguindo as regras
do Algoritmo de Tarry, regressaremos ao vértice inicial, depois de ter
percorrido cada aresta do grafo 22 vezes em sentidos opostos.
Tirado de https://www.geeksforgeeks.org/mathematics-graph-theory-basics-set-1/?
ref=lbp
Characteristics of graphs:
1. Adjacent node: A node ‘v’ is said to be adjacent node of node ‘u’ if and only if
there exists an edge between ‘u’ and ‘v’.
2. Degree of a node: In an undirected graph the number of nodes incident on a node
is the degree of the node.
In case of directed graph ,Indegree of the node is the number of arriving
edges to a node.
Outdegree of the node is the number of departing edges to a node.
1.
2. Path: A path of length ‘n’ from node ‘u’ to node ‘v’ is defined as sequence of n+1
nodes.
P(u,v)=(v0,v1,v2,v3…….vn)
A path is simple if all the nodes are distinct,exception is source and destination
are same.
1. Isolated node: A node with degree 0 is known as isolated node.Isolated node can
be found by Breadth first search(BFS). It finds its application in LAN network in
finding whether a system is connected or not.
Types of graphs:
1. Directed graph:
A graph in which the direction of the edge is defined to a particular node is a
directed graph.
Directed Acyclic graph: It is a directed graph with no cycle.For a vertex
‘v’ in DAG there is no directed edge starting and ending with vertex
‘v’.
a) Application :Critical game analysis,expression tree evaluation,game
evaluation.
Tree: A tree is just a restricted form of graph.That is, it is a DAG with
a restriction that a child can have only one parent.
Undirected graph:
A graph in which the direction of the edge is not defined.So if an edge exists between
node ‘u’ and ‘v’,then there is a path from node ‘u’ to ‘v’ and vice versa.
3. Connected graph: A graph is connected when there is a path between every
pair of vertices.In a connected graph there is no unreachable node.
4. Complete graph: A graph in which each pair of graph vertices is connected by
an edge.In other words,every node ‘u’ is adjacent to every other node ‘v’ in
graph ‘G’.
5. Biconnected graph: A connected graph which cannot be broken down into any
further pieces by deletion of any vertex.It is a graph with no articulation
point.
A graph is a structure amounting to a set of objects in which some pairs of the objects
are in some sense “related”. The objects of the graph correspond to vertices and the
relations between them correspond to edges. A graph is depicted diagrammatically as
a set of dots depicting vertices connected by lines or curves depicting edges.
Formally,
“A graph G(V,E) consists of V, a non-empty set of vertices (or nodes) and E, a set
of edges. Each edge has either one or two vertices associated with it, called
its endpoints.”
Types of graph :There are several types of graphs distinguished on the basis of edges,
their direction, their weight etc.
1. Simple graph – A graph in which each edge connects two different vertices and
where no two edges connect the same pair of vertices is called a simple graph. For
example, Consider the following graph –
The above graph is a simple graph, since no vertex has a self-loop and no two vertices
have more than one edge connecting them.
The edges are denoted by the vertices that they connect-{A,B} is the edge connecting
vertices A and B.
2. Multigraph – A graph in which multiple edges may connect the same pair of
vertices is called a multigraph.
Since there can be multiple edges between the same pair of vertices,
the multiplicity of edge tells the number of edges between two vertices.
The above graph is a multigraph since there are multiple edges between B and C. The
multiplicity of the edge {B,C} is 2.
In some graphs, unlike the one’s shown above, the edges are directed. This means
that the relation between the objects is one-way only and not two-way. The direction
of the edges may be important in some applications.
Based on whether the edges are directed or not we can have directed graphs and
undirected graphs. This property can be extended to simple graphs and multigraphs
to get simple directed or undirected simple graphs and directed or undirected
multigraphs.
Basic graph Terminology :
In the above discussion some terms regarding graphs have already been explained
such as vertices, edges, directed and undirected edges etc. There are more terms which
describe properties of vertices and edges.
Adjacency – In a graph G two vertices v1 and v2 are said to be adjacent if they
are the endpoints of an edge. The edge {v1,v2}-e is said to be incident with the
vertices.
In case the edge is directed, v1 is said to be adjacent to v2 and v2 is said to be
adjacent from v1. Here, v1is said to be the initial vertex and v2 is said to the
terminal vertex.
Degree – The degree of a vertex is the number of edges incident with it, except
the self-loop which contributes twice to the degree of the vertex. Degree of a
vertex v1 is denoted as deg (v1).
In case of directed graphs, the degree is further classified as in-degree and
out-degree. The in-degree of a vertex is the number of edges with the given
vertex as the terminal vertex. The out-degree of a vertex is the number of
edges with the given vertex as the initial vertex. In-degree is denoted as deg -
(v1) and out-degree is denoted as deg + (v1)
Note: If a vertex has zero degree, it is called isolated. If the degree is one then it’s
called pendant.
Handshaking Theorem :
What would one get if the degrees of all the vertices of a graph are added?
In case of an undirected graph, each edge contributes twice, once for its initial
vertex and second for its terminal vertex. So the sum of degrees is equal to twice
the number of edges.
This fact is stated in the Handshaking Theorem.
1. Complete Graphs –
A complete graph on n vertices, denoted by Kn, is a simple graph that contains
exactly one edge between each pair of distinct vertices.
The graphs Kn, for n = 1, 2, 3, 4, 5, 6, are displayed in Figure 3. A simple graph
for which there is at least one pair of distinct vertex not connected by an edge is
called noncomplete.
Total number of edges are n*(n-1)/2 with n vertices in complete graph.
2. Cycles
A cycle Cn, n ≥ 3, consists of n vertices v1, v2, … , vn and edges {v1, v2}, {v2,
v3}, … , {vn−1, vn}, and {vn, v1}. The cycles C3, C4, C5, and C6 are displayed
below
Cycle with n vertices is denoted as Cn.
Total number of edges are n with n vertices in cycle graph.
3. Wheels –
A wheel is just like a cycle, with one additional vertex which is connected to
every other vertex. Thus, we obtain a wheel Wn when we add an additional
vertex to a cycle Cn, for n ≥ 3, and connect this new vertex to each of the n
vertices in Cn, by new edges.
Wheels of n vertices with 1 addition vertex are denoted by Wn.
Total number of edges are 2*(n-1) with n vertices in wheel graph.
4. Hypercube
An n-dimensional hypercube, or n-cube, denoted by Qn, is a graph that has
vertices representing the 2n bit strings of length n. Two vertices are adjacent,
ie, connected by edges, if and only if the bit strings that they represent differ
in exactly one bit position. A hypercube of 2n vertices is denoted by Qn. Total
number of edges are n*2 (n-1) with 2n vertices in cube graph.
5. Bipartite Graphs –
A simple graph G is called bipartite if its vertex set V can be divided/partitioned
into two disjoint sets V1 and V2 such that every edge in the graph connects a
vertex in V1 and a vertex in V2 (so that no edge in G connects either two
vertices in V1 or two vertices in V2), ie, edge in G has its initial vertex in the
first set and the terminal vertex in the second set.
When this condition holds, we call the pair (V1, V2) a bipartition of the vertex
set V of G.
Total number of edges are (n*m) with (n+m) vertices in bipartite graph.
Theorem
A simple graph is bipartite if and only if it is possible to assign one of two different
colors to each vertex of the graph so that no two adjacent are assigned the
same color.
A bipartite graph with m and n vertices in its two disjoint subsets is said to be
complete if there is an edge from every vertex in the first set to every vertex in the
second set, for a total of mn edges. A complete bipartite graph with m vertices in
the first set and n vertices in the second set is denoted as Km,n.
Another useful criterion for determining whether a graph is bipartite is based on the
notion of a path. A graph is bipartite if and only if it is not possible to start at a
vertex and return to this vertex by traversing an odd number of distinct edges.
Complete Bipartite Graphs
A complete bipartite graph Km,n is a graph that has its vertex set partitioned into two
subsets of m and n vertices, respectively with an edge between two vertices if and
only if one vertex is in the first subset and the other vertex is in the second subset.
The complete bipartite graphs K2,3, K3,3, K3,5, and K2,6 are displayed in Figure:
When edges and vertices are removed from a graph, without removing endpoints of any
remaining edges, a smaller graph is obtained.
Such a graph is called a subgraph of the original graph.
Definition:
A subgraph of a graph G = (V, E) is a graph H = (W, F), where W ⊆ V and F ⊆ E.
A subgraph H of G is a proper subgraph of G if H ≠ G.
Given a set of vertices of a graph, we can form a subgraph of this graph with these
vertices and the edges of the graph that connect them.
Definition:
Let G = (V, E) be a simple graph. The subgraph induced by a subset W of the vertex
set V is the graph (W, F), where the edge set F contains an edge in E if and only if
both endpoints of this edge are in W.
Given a graph G = (V, E) and an edge e ∈ E, we can produce a subgraph of G by removing the
edge e.
The resulting subgraph, denoted by G − e, has the same vertex set V as G. Its edge set is E −
{e}. Hence:
G − e = (V, E − {e}).
We can also add an edge e to a graph to produce a new larger graph when this edge connects
two vertices already in G. We denote by G + e the new graph produced by adding a new edge
e, connecting two previously non-incident vertices, to the graph G.
Hence:
G + e = (V, E ∪ {e})
The vertex set of G + e is the same as the vertex set of G and the edge set is the union of the
edge set of G and the set {e}.
When we remove a vertex v and all edges incident to it from G = (V, E), we produce a
subgraph, denoted by G − v.
GRAPH UNIONS
Two or more graphs can be combined in various ways. The new graph that contains all the
vertices and edges of these graphs is called the union of the graphs.
Definition:
The union of two simple graphs G1 = (V1, E1) and G2 = (V2, E2) is the simple graph with vertex
set V1 ∪ V2 and edge set E1 ∪ E2. The union of G1 and G2 is denoted by G1 ∪ G2.
Exercises:
1.
Maximum number of edges in a n – node undirected graph without self loops is
(A) n2
(B) n(n – 1)/2
(C) n – 1
(D) (n + 1) (n)/2
Answer: (B)
Somatorio dos graus: 6*2 + 3*4 + 3*(x-9)=2*27 (2 vezes o número de arestas é igual
ao somatório do grau dos vértices);
Logo:
x=19
Answer: (D)
Explanation: The idea is to use Handshaking Lemma :- In any graph, the sum of all
the vertex-degree is equal to twice the number of edges.
Let x = Total Number of Vertices.
By Handshaking Lemma
x-9 = 10
x = 19
3.
Which of the following statements is/are TRUE for an undirected graph?
P: Number of odd degree vertices is even
Q: Sum of degrees of all vertices is even
(A) P Only
(B) Q Only
(C) Both P and Q
(D) Neither P nor Q
Answer: (C)
4.
DIFICIL- NÃO PERCEBI
Consider an undirected graph G where self-loops are not allowed. The vertex set of G
is {(i, j): 1 <= i <= 12, 1 <= j <= 12}. There is an edge between (a, b) and (c, d) if |a −
c| <= 1 and |b − d| <= 1.
The number of edges in this graph is __________.
(A) 500
(B) 502
(C) 506
(D) 510
Answer: (C)
Explanation:
Given:
The vertex set of G is {(i, j): 1 <= i <= 12, 1 <= j <= 12}.
There is an edge between (a, b) and (c, d) if |a − c| <= 1 and
|b − d| <= 1.
There can be total 12*12 possible vertices. The vertices are (1, 1),
(1, 2) ....(1, 12) (2, 1), (2, 2), ....
For (1, 1), there can be an edge to (1, 2), (2, 1), (2, 2). Note that
there can be self-loop as mentioned in the question.
Same is count for (12, 12), (1, 12) and (12, 1)
For (1, 2), there can be an edge to (1, 1), (2, 1), (2, 2), (2, 3),
(1, 3)
Same is count for (1, 3), (1, 4)....(1, 11), (12, 2), ....(12, 11)
For (2, 2), there can be an edge to (1, 1), (1, 2), (1, 3), (2, 1),
(2, 3), (3, 1), (3, 2), (3, 3)
Same is count for remaining vertices.
For all pairs (i, j) there can total 8 vertices connected to them if
i and j are not in {1, 12}
There are total 100 vertices without a 1 or 12. So total 800 edges.
5.
DIFICIL- NÃO PERCEBI
The 2n vertices of a graph G corresponds to all subsets of a set of size n, for n >= 6 .
Two vertices of G are adjacent if and only if the corresponding sets intersect in
exactly two elements.
The number of vertices of degree zero in G is:
(A) 1
(B) n
(C) n+1
(D) 2n
Answer: (C)
Explanation: There are n nodes which are single and 1 node which belong to empty
set. And since they are not having 2 or more elements so they won’t be connected to
anyone hence total number of nodes with degree 0 are n+1.
Answer: (A)
Let G be an arbitrary graph with n nodes and k components. If a vertex is removed from
G, the number of components in the resultant graph must necessarily lie between
k and n
A
k - 1 and k + 1
B
k - 1 and n - 1
C
k + 1 and n - k
D
Answer: (C)
Consider an undirected random graph of eight vertices. The probability that there is an
edge between a pair of vertices is 1/2. What is the expected number of unordered
cycles of length three?
(A) 1/8
(B) 1
(C) 7
(D) 8
Answer: (C)
Consider an undirected random graph of eight vertices. The probability that there is an
edge between a pair of vertices is 1/2. What is the expected number of unordered
cycles of length three?
(A) 1/8
(B) 1
(C) 7
(D) 8
Answer: (C)
Explanation: A cycle of length 3 can be formed with 3 vertices. There can be total
8C3 ways to pick 3 vertices from 8. The probability that there is an edge between two
vertices is 1/2. So expected number of unordered cycles of length 3 = (8C3)*(1/2)^3 =
7
Graph Types and Applications
A graph G = (V, E) consists of a set of vertices V = { V1, V2, . . . } and set of edges E
= { E1, E2, . . . }. The set of unordered pairs of distinct vertices whose elements are
called edges of graph G such that each edge is identified with an unordered pair (Vi,
Vj) of vertices.
The vertices (Vi, Vj) are said to be adjacent if there is an edge Ek which is associated
to Vi and Vj. In such a case Vi and Vj are called end points and the edge Ek is said to
be connect/joint of Vi and Vj.
´
Trivial Graph: A graph is said to be trivial if a finite graph contains only one vertex
and no edge.
Simple Graph: A simple graph is a graph which does not contains more than one
edge between the pair of vertices. A simple railway tracks connecting different cities
is an example of simple graph.
Complete graph
A simple graph with n vertices is called a complete graph if the degree of each vertex
is n-1, that is, one vertex is attach with n-1 edges. A complete graph is also called Full
Graph.
Multi Graph: Any graph which contain some parallel edges but doesn’t contain
any self-loop is called multi graph. For example A Road Map.
Parallel Edges: If two vertices are connected with more than one edge
than such edges are called parallel edges that is many roots but one
destination.
Loop: An edge of a graph which join a vertex to itself is called loop or
a self-loop.
Null Graph: A graph of order n and size zero that is a graph which contain n number
of vertices but do not contain any edge.
Pseudo Graph: A graph G with a self loop and some multiple edges is called pseudo
graph.
Regular Graph: A simple graph is said to be regular if all vertices of a graph G are of
equal degree. All complete graphs are regular but vice versa is not possible.
Bipartite Graph: A graph G = (V, E) is said to be bipartite graph if its vertex set
V(G) can be partitioned into two non-empty disjoint subsets. V1(G) and V2(G) in
such a way that each edge e of E(G) has its one end in V1(G) and other end in V2(G).
The partition V1 U V2 = V is called Bipartite of G.
Here in the figure:
V1(G)={V5, V4, V3}
V2(G)={V1, V2}
Labelled Graph: If the vertices and edges of a graph are labelled with name, data or
weight then it is called labelled graph. It is also called Weighted Graph.
Digraph Graph: A graph G = (V, E) with a mapping f such that every edge maps
onto some ordered pair of vertices (Vi, Vj) is called Digraph. It is also called Directed
Graph. Ordered pair (Vi, Vj) means an edge between Vi and Vj with an arrow
directed from Vi to Vj.
Here in the figure:
e1 = (V1, V2)
e2 = (V2, V3)
e4 = (V2, V4)
Subgraph: A graph G = (V1, E1) is called subgraph of a graph G(V, E) if V1(G) is a
subset of V(G) and E1(G) is a subset of E(G) such that each edge of G1 has same end
vertices as in G.
Types of Subgraph:
Vertex disjoint subgraph: Any two graph G1 = (V1, E1) and G2 = (V2,
E2) are said to be vertex disjoint of a graph G = (V, E) if V1(G1)
intersection V2(G2) = null. In figure there is no common vertex between
G1 and G2.
Edge disjoint subgraph: A subgraph is said to be edge disjoint if E1(G1)
intersection E2(G2) = null. In figure there is no common edge between G1
and G2.
Note: Edge disjoint subgraph may have vertices in common but vertex disjoint graph
cannot have common edge, so vertex disjoint subgraph will always be an edge disjoint
subgraph.
Cyclic Graph: A graph G consisting of n vertices and n> = 3 that is V1, V2, V3- –
– – – – – – Vn and edges (V1, V2), (V2, V3), (V3, V4)- – – – – – – – — -(Vn, V1)
are called cyclic graph.
Walks, Trails, Paths, Cycles and Circuits in Graph
Generally, a walk is defined to be an alternating sequence of vertices and edges of a graph, v0,
e1, v1, e2, … , vn−1, en, vn, where vi−1 and vi are the endpoints of ei for i = 1, 2, … , n. When
this terminology is used, closed walk is used instead of circuit to indicate a walk that begins
and ends at the same vertex, and trail is used to denote a walk that has no repeated edge
(replacing the term simple path). When this terminology is used, the terminology path is often
used for a trail with no repeated vertices;
1. Walk – (PERCURSO)
Informally, a walk is a sequence of edges that begins at a vertex of a graph and
travels from vertex to vertex along edges of the graph. As the walk travels along
its edges, it visits the vertices along this walks, that is, the endpoints of these
edges.
Definition:
Let n be a nonnegative integer and G an undirected graph. A walk of length n from u
to v in G is a sequence of n edges e1, … , en of G for which there exists a sequence
x0 = u, x1, … , xn−1, xn = v of vertices such that ei has, for i = 1, … , n, the
endpoints xi−1 and xi .
When the graph is simple, we denote this walk by its vertex sequence x0, x1, … , xn
(because listing these vertices uniquely determines the path).
The walk is a closed walk if it begins and ends at the same vertex, that is, if u = v,
and has length greater than zero.
The walk or closed walk is said to pass through the vertices x1, x2, … , xn−1 or
traverse the edges e1, e2, … , en.
A walk or closed walk is called a trail if it does not contain the same edge more than
once.
Thus, a walk is simply a sequence of vertices and edges of a graph i.e. if we traverse a
graph then we get a walk.
Note: Vertices and Edges can be repeated.
Here, 1->2->3->4->2->1->3 is a walk.
Walk can be open or closed.
Open walk- A walk is said to be an open walk if the starting and ending vertices are
different i.e. the origin vertex and terminal vertex are different.
Closed walk- A walk is said to be a closed walk if the starting and ending vertices are
identical i.e. if a walk starts and ends at the same vertex, then it is said to be a closed
walk.
In the above diagram:
1->2->3->4->5->3 is an open walk.
1->2->3->4->5->3->1 is a closed walk.
2. Trail – (PISTA)
4. Path – CAMINHO
It is a trail in which neither vertices nor edges are repeated, i.e. if we traverse a
graph such that we do not repeat a vertex and nor we repeat an edge. As path is also a
trail, thus it is also an open walk.
Vertex not repeated
Edge not repeated
Note that for closed sequences start and end vertices are the only ones that can repeat.
Graph measurements: length, distance, diameter, eccentricity, radius,
center
A graph is defined as set of points known as ‘Vertices’ and line joining these points is
known as ‘Edges’. It is a set consisting of where ‘V’ is vertices and ‘E’ is edge.
Vertices: {A, B, C, D, E, F}
Edges: {{A, B}, {A, D}, {A, E}, {B, C}, {C, E}, {C, F}, {D, E}, {E, F}}
graph.
Length of the graph: 8
AB, BC, CD, DE, EF, FA, AC, CE
2. The distance between two Vertices –
The distance between two vertices in a graph is the number of edges in a shortest
or minimal path. It gives the available minimum distance between two edges. There
can exist more than one shortest path between two vertices.
6. Diameter of graph –
The diameter of graph is the maximum
distance between the pair of vertices. It can
also be defined as the maximal distance between the pair of vertices. Way to
solve it is to find all the paths and then find the maximum of all.
ll.
Diameter: 3
BC → CF → FG
4. Radius of graph –A radius of the graph exists only if it has the diameter. The
minimum among all the maximum distances between a vertex to all other vertices
is considered as the radius of the Graph G.It is denoted as r(G).
Radius: 2
All available minimum radius:
BC → CF,
BC → CE,
BC → CD,
BC → CA
5. Centre of graph –
It consists of all the vertices whose eccentricity is minimum. Here the eccentricity is
equal to the radius. For example, if the school is at the centre of town it will reduce
the distance buses has to travel.
Centre: A
6. Eccentricity of graph –
It is defined as the maximum distance of one vertex from other vertex.The
maximum distance between a vertex to all other vertices is considered as the
eccentricity of the vertex. It is denoted by e(V).
Eccentricity from:
(A, A) = 0
(A, B) = 1
(A, C) = 2
(A, D) = 1
Maximum value is 2, So Eccentricity is 2
7.
Euler and Hamiltonian Paths
Certain graph problems deal with finding a path between two vertices such that each
edge is traversed exactly once, or finding a walk between two vertices while
visiting each vertex exactly once. These walks are better known as Euler
walks and Hamiltonian path respectively.
The Euler path problem was first proposed in the 1700’s.
There are simple criteria for determining whether a multigraph has a Euler trail
or a Euler circuit.
Thus, for any multigraph to have a Euler circuit, all the degrees of the vertices
must be even.
Theorem – “A connected multigraph (and simple graph) with at least two
vertices has a Euler circuit if and only if each of its vertices has an even
degree.”
Proof of the above statement is that every time a circuit passes through a
vertex, it adds twice to its degree. Since it is a circuit, it starts and ends at the
same vertex, which makes it contribute one degree when the circuit starts and
one when it ends. In this way, every vertex has an even degree.
Since the konigsberg graph has vertices having odd degrees, a Euler circuit
does not exist in the graph.
Theorem – “A connected multigraph (and simple graph) has an Euler trail but not an
Euler circuit if and only if it has exactly two vertices of odd degree.”
The proof is an extension of the proof given above. Since a path may start and end at
different vertices, the vertices where the path starts and ends are allowed to have odd
degrees.
Example – Which graphs shown below have an Euler path or Euler circuit?
Solution – G1 has two vertices of odd degree a and d and the rest of them have
even degree. So this graph has an Euler trail but not an Euler circuit. The trail
starts and ends at the vertices of odd degree. The trail is- a c d a b d.
G2 has four vertices all of even degree, so it has a Euler circuit. The circuit is – a d
bacda
Hamiltonian paths and cycles :
Hamiltonian Path – A path (open) in a graph G that passes through every vertex
exactly once is called a Hamiltonian path.
Hamiltonian cycle – A cycle in a graph G that passes through every vertex
exactly once is called a Hamiltonian cycle.
Unlike Euler trails and circuits, there is no simple necessary and sufficient criteria
to determine if there are any Hamiltonian paths or cycles in a graph. But there are
certain criteria which rule out the existence of a Hamiltonian path in a graph,
such as- if there is a vertex of degree one in a graph then it is impossible for it
to have a Hamiltonian path.
There are certain theorems which give sufficient but not necessary conditions for
the existence of Hamiltonian graphs:
As mentioned above that the above theorems are sufficient but not necessary
conditions for the existence of a Hamiltonian circuit in a graph, there are certain
graphs which have a Hamiltonian circuit but do not follow the conditions in the
above-mentioned theorem. For example, the cycle C5 has a Hamiltonian circuit but
does not follow the theorems.
Note: Kn is Hamiltonian cycle for n>=3
There are many practical problems which can be solved by finding the optimal
Hamiltonian ccyle. One such problem is the Travelling Salesman Problem which asks
for the shortest route through a set of cities.
Example 1- Does the following graph have a Hamiltonian Cycle?
Solution- Yes, the above graph has a Hamiltonian circuit. The solution is –
Solution- No the above graph does not have a Hamiltonian circuit as there are two
vertices with degree one in the graph.
Exercises:
1.
Which of the following graphs has an Eulerian circuit?
(A) Any k-regular graph where k is an even number.
(B) A complete graph on 90 vertices
(C) The complement of a cycle on 25 vertices
(D) None of the above
Answer: (C)
Explanation: A graph has Eulerian Circuit if following conditions are true.
….a) All vertices with non-zero degree are connected. We don’t care about vertices
with zero degree because they don’t belong to Eulerian Cycle or Path (we only
consider all edges).
….b) All vertices have even degree.
Let us analyze all options.
A) Any k-regular graph where k is an even number. is not Eulerian as a k regular
graph may not be connected (property b is true, but a may not)
B) A complete graph on 90 vertices is not Eulerian because all vertices have degree
as 89 (property b is false)
C) The complement of a cycle on 25 vertices is Eulerian. In a cycle of 25 vertices, all
vertices have degree as 2. In complement graph, all vertices would have degree as 22
and graph would be connected.
NÃO PERCEBI
2.
G is a simple undirected graph. Some vertices of G are of odd degree. Add a node v to
G and make it adjacent to each odd degree vertex of G. The resultant graph is sure to
be
(A) regular
(B) Complete
(C) Hamiltonian
(D) Euler
Answer: (D)
Explanation: For a graph to be Euler graph all the degrees must be Even for all
nodes. In any graph all the Odd degree nodes are connected with a node.
And number of Odd degree vertices should be even.
So degree of this new node will be Even and as a new edge is formed between this
new node and all other nodes of Odd degree hence here is not a single node exists
with degree Odd
Consider an electronic circuit having several nodes with connections between them. Is
it possible to print that circuit on a single board such that none of the connections
cross each other i.e. they do not overlap or intersect?
This question can be answered if we know about planarity of graphs.
Planarity – “A graph is said to be planar if it can be drawn on a plane without any
edges crossing. Such a drawing is called a planar representation of the graph.”
Important Note – A graph may be planar even if it is drawn with crossings, because
it may be possible to draw it in a different way without crossings.
For example consider the complete graph K 4 and its two possible planar
representations –
There are a total of 6 regions with 5 bounded regions and 1 unbounded region .
All the planar representations of a graph split the plane in the same number of regions.
Euler found out the number of regions in a planar graph as a function of the number of
vertices and number of edges in the graph.
Graph Coloring –
If you ever decide to create a map and need to color the parts of it optimally, feel
lucky because graph theory is by your side. What is the maximum number of colors
required to color the regions of a map? This question along with other similar ones
have generated a lot of results in graph theory.
First, let us define the constraint of coloring in a formal way-
Coloring – “A coloring of a simple graph is the assignment of a color to each vertex
of the graph such that no two adjacent vertices are assigned the same color.”
A simple solution to this problem is to color every vertex with a different color to get
a total of colors. But in some cases, the actual number of colors required could be
less than this.
chromatic number –“The least number of colors required to color a graph is called
its chromatic number. It is denoted by X(G).”
For planar graphs the finding the chromatic number is the same problem as finding the
minimum number of colors required to color a planar graph.
4 color Theorem – “The chromatic number of a planar graph is no greater than
4.”
Example 1 – What is the chromatic number of the following graphs?
?
Solution – In graph G, the chromatic number is atleast three since the vertices a, b,
and f are connected to each other.
The following color assignment satisfies the coloring constraint –
a – Red
b – Green
c – Blue
d – Red
e – Green
f – Blue
g – Red
Therefore the chromatic number of G is 3.
In graph H since a and d are also connected, therefore the chromatic number if 4.
Example 2 – What is the chromatic number of Kn?
Solution – Since every vertex is connected to every other vertex in a complete
graph, the chromatic number is n.
Example 3 – What is the chromatic number of Cn?
Solution – If the vertex are colored in an alternating fashion, the C n cycle graph
requires 2 colors. If n is odd, then the last vertex would have the same color as the
first vertex, so the chromatic number will be 3. But if it is even, then first and last
vertices will be of different color and the chromatic number will be 2.
Example 4 – What is the chromatic number of K m,n?
Solution – In the bi-partite graph K m,n,lool, the vertices in are divided into two sets,
such that there is no edge between vertices in the same set. Therefore the
chromatic number of any bipartite graph is 2. One set of vertices can be assigned
one color and the other can be assigned a different color for a total of 2 colors. It
will satisfy the coloring constraint since the vertices of the same set are not
connected
Graph Isomorphisms and Connectivity
Isomorphism :
Consider the following two graphs –
Definition:
The simple graphs G1 = (V1, E1) and G2 = (V2, E2) are isomorphic if there exists a
one-to one and onto function f from V1 to V2 with the property that a and b are
adjacent in G1 if and only if f(a) and f(b) are adjacent in G2, for all a and b in V1.
Such a function f is called an isomorphism.
∗ Two simple graphs that are not isomorphic are called non-isomorphic.
In other words, there is a one-to-one correspondence between vertices of the two
graphs that preserves the adjacency relationship. Isomorphism of simple graphs is an
equivalence relation (reflexive, simetrica, transitive).
Proving that the above graphs are isomorphic was easy since the graphs were
small, but it is often difficult to determine whether two simple graphs are
isomorphic. This is because there are n! possible bijective functions between the
vertex sets of two simple graphs with n vertices. Testing the correspondence for
each of the functions is impractical for large values of n.
Although sometimes it is not that hard to tell if two graphs are not isomorphic. In
order, to prove that the given graphs are not isomorphic, we could find out some
property that is characteristic of one graph and not the other. If they were
isomorphic then the property would be preserved, but since it is not, the graphs are
not isomorphic.
Such a property that is preserved by isomorphism is called graph-invariant.
Some graph-invariants include- the number of vertices, the number of edges, degrees
of the vertices, and length of cycle, etc.
You can say given graphs are isomorphic if they have:
1. Equal number of vertices.
2. Equal number of edges.
3. Same degree sequence
4. Same number of circuit of particular length
To show that a function f from the vertex set of a graph G to the vertex set of a
graph H is an isomorphism, we need to show that f preserves the presence and
absence of edges. One helpful way to do this is to use adjacency matrices.
In particular, to show that f is an isomorphism, we can show that the adjacency
matrix of G is the same as the adjacency matrix of H, when rows and columns are
labeled to correspond to the images under f of the vertices in G that are the labels
of these rows and columns in the adjacency matrix of G.
Important Note : The complementary of a graph has the same vertices and has edges
between any two vertices if and only if there was no edge between them in the original
graph. Consequently, a graph G is said to be self-complementary if the graph and its
complement are isomorphic.
Connectivity :
Most problems that can be solved by graphs, deal with finding optimal paths,
distances, or other similar information. Almost all of these problems involve finding
paths between graph nodes.
In case the graph is directed, the notions of connectedness have to be changed a bit.
This is because of the directions that the edges have.
Formally,
“A directed graph is said to be strongly connected if there is a path from a to b and
b to a where a and b are vertices in the graph. The graph is weakly connected if
the underlying undirected graph is connected.”
Cut set – In a connected graph G a cut-set is a set of edges which when removed from
G leaves G disconnected, provided there is no proper subset of these edges
disconnects G.
Solution – Both the graphs have 6 vertices, 8 edges and the degree sequence is the
same. However the second graph has a circuit of length 3 and the minimum length
of any circuit in the first graph is 4. Hence the given graphs are not isomorphic.
(A) A
(B) B
(C) C
(D) D
Answer: (B)
Let G be a complete undirected graph on 6 vertices. If vertices of G are
labeled, then the number of distinct cycles of length 4 in G is equal to
(A) 15
(B) 30
(C) 45
(D) 360
Answer: (C)
Let G=(V,E) be a directed graph where V is the set of vertices and E the set of
edges. Then which one of the following graphs has the same strongly
connected components as G ?
(A) A
(B) B
(C) C
(D) D
Answer: (B)
Explanation: If we reverse directions of all arcs in a graph, the new graph has
same set of strongly connected components as the original graph
Answer: (D)
Answer: (D)
Answer: (B)
Given an undirected graph, a matching is a set of edges, such that no two edges
share the same vertex.
In other words, matching of a graph is a subgraph where each node of the subgraph
has either zero or one edge incident to it.
A vertex is said to be matched if an edge is incident to it, free otherwise.
Possible matchings of G, here the red edges denote the matching –
Adding any edge to any of the above graphs would result in them no longer being a
matching.
Maximum Matching – A matching M of graph G is said to be maximum if it is
maximal and has the maximum number of edges.
There may be many possible maximum matchings of a graph.
Every maximum matching is a maximal matching but not every maximal matching is
a maximum matching.
For example, in the first figure G3 is a maximum matching and in the second figure,
the second and third graphs are maximum matchings.
How many perfect matchings are there in a complete graph of 6 vertices ?
(A) 15
(B) 24
(C) 30
(D) 60
Answer: (A)
Explanation: A perfect matching, every vertex of the graph is incident to exactly one
edge of the matching. A perfect matching is therefore a matching of a graph
containing n/2 edges, the largest possible, meaning perfect matchings are only
possible on graphs with an even number of vertices.
Betweenness Centrality (Centrality Measure)
tree
----
j <-- root
/ \
f k
/ \ \
a h z <-- leaves
Why Trees?
1. One reason to use trees might be because you want to store information that
naturally forms a hierarchy. For example, the file system on a computer:
file system
-----------
/ <-- root
/ \
... home
/ \
ugrad course
/ / | \
... cs101 cs112 cs113
2. Trees (with some ordering e.g., BST) provide moderate access/search (quicker than
Linked List and slower than arrays).
3. Trees provide moderate insertion/deletion (quicker than Arrays and slower than
Unordered Linked Lists).
4. Like Linked Lists and unlike Arrays, Trees don’t have an upper limit on number of
nodes as nodes are linked using pointers.
Main applications of trees include:
1. Manipulate hierarchical data.
2. Make information easy to search (see tree traversal).
3. Manipulate sorted lists of data.
4. As a workflow for compositing digital images for visual effects.
5. Router algorithms
6. Form of a multi-stage decision-making (see business chess).
Binary Tree: A tree whose elements have at most 2 children is called a binary tree.
Since each element in a binary tree can have only 2 children, we typically name them
the left and right child.
Binary Tree Representation in C: A tree is represented by a pointer to the topmost
node in tree. If the tree is empty, then value of root is NULL.
A Tree node contains following parts.
1. Data
2. Pointer to left child
3. Pointer to right child
In C, we can represent a tree node using structures. Below is an example of a tree
node with an integer data.
A tree whose elements have at most 2 children is called a binary tree. Since each element
in a binary tree can have only 2 children, we typically name them the left and right child.
Given n nodes of a forest (collection of trees), find the number of trees in the forest.
Examples :
Input : edges[] = {0, 1}, {0, 2}, {3, 4}
Output : 2
Explanation : There are 2 trees
0 3
/\ \
1 2 4
Given a tree with v vertices, find the level of each node in a tree from the source node.
Examples:
Input :
Output : Node Level
0 0
1 1
2 1
3 2
4 2
5 2
6 2
7 3
Explanation :
Input:
Output : Node Level
0 0
1 1
2 1
3 2
4 2
Explanation: