Você está na página 1de 64

https://resumos.leic.

pt/md/grafos

Grafos - Início | Resumos LEIC-A

Teorema 3 - Teorema de Euler


Se tivermos um grafo que não seja Euleriano, podemos duplicar cada aresta e
dessa maneira todos os vértices terão grau par, assim já é Euleriano.
NOTA: Outra solução é percorrer cada aresta duas vezes, em vez de duplicar.

Teorema 4 - Teorema de Lucas

Um multigrafo G conexo com 2n vértices ímpares pode ser descrito por


exatamente n  atalhos abertos que não partilham arestas.
Árvores

Informação mais detalhada sobre Árvores

Árvore

Grafo conexo que não tem ciclos.

Teoremas de Árvores
Teorema 1

Se TT é uma árvore de ordem pp e tamanho qq, então

q = p-1q=p−1

Teorema 2

Um grafo gg de ordem pp é uma árvore, se e só se é conexo e tem


tamanho q=p-1q=p−1.

Definições
Árvore de cobertura

Seja gg um grafo, TT é a sua Árvore de Cobertura se:

 É uma árvore
 É um subgrafo de gg que contém todos os vértices

Custo de árvore

Dada uma rede (V,E,c)(V,E,c), o custo de uma árvore de


cobertura TT da rede é
o somatório de todos os valores das arestas de TT.

Árvore de cobertura mínima

Árvore de cobertura de uma rede RR, cujo custo é menor ou igual ao


custo de qualquer outra Árvore de cobertura de RR.

Árvore Económica

Árvore de cobertura construída através do Algoritmo de Kruskal.


Algoritmo de Fleury
Com este Algoritmo consegue-se percorrer um atalho euleriano
fechado num multigrafo euleriano.

1. Começa-se num vértice qualquer


2. Se houver mais que 11 aresta possível a percorrer, escolhe-se uma que não
seja Ponte (não interessa qual, desde que não seja uma Ponte)
3. Só se atravessam as Pontes em último caso (quando já não há mais arestas
disponíveis).

Relembrar: Ponte é uma aresta que, se removida, cria uma nova componente.


Exemplo

Algoritmo Fleury - Multigrafo Atravessável


O Algoritmo de Fleury foi concebido para multigrados eulerianos.
Mas, também o podemos aplicar, informalmente, em multigrafos
atravessáveis.
Para isso, basta começar num vértice ímpar, é a única mudança no Algoritmo.
Mas, neste caso, não vamos acabar no mesmo vértice, mas sim no outro vértice
ímpar. Reparem que, se, num multigrafo atravessável, ligarmos os dois
vértices ímpares com uma aresta, ficamos com um multigrafo euleriano.
Nesse caso, já poderíamos acabar no vértice inicial.
Desvantagens
Não funciona em Labirintos se não o conhecermos, uma vez que nesses caso
não sabemos se um aresta (caminho do Labirinto) é Ponte ou não.

Algoritmo de Trémaux

Com as regras deste Algoritmo, qualquer um pode sair de qualquer labirinto.

Passamos agora à descrição do Algoritmo:

1. Sempre que chegamos a um vértice não visitado anteriormente, seguimos por


uma aresta também não percorrida, qualquer.
2. Sempre que chegarmos a um vértice através de uma aresta ainda não
percorrida anteriormente, se chegarmos a um vértice já visitado ou a um beco
sem saída, voltamos para o vértice de onde viemos pela aresta.
3. Sempre que chegarmos a um vértice através de uma aresta que já tinha sido
percorrida anteriormente e chegarmos a um vértice já visitado, escolhemos a
aresta ainda não percorrida que incide no vértice. Se não existir, escolhemos
percorrer uma aresta que já tenha sido percorrida apenas uma vez.

Exemplo
Algoritmo de Tarry

Se chegarmos a um vértice, escolhemos continuar por qualquer aresta que não


tenha sido percorrida 22 vezes (dando prioridade às arestas ainda não
percorridas), com exceção da aresta onde chegamos pela primeira vez ao
vértice atual.
Só percorremos essa aresta em último caso, ou seja, se for um beco sem saída,
ou se as outras arestas já tiverem sido percorridas 22 vezes.

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

Graph Theory Basics – Set 1

A graph is a data structure that is defined by two components :


1. A node or a vertex.
2. An edge E or ordered pair is a connection between two nodes u,v that is
identified by unique pair(u,v). The pair (u,v) is ordered because (u,v) is not same
as (v,u) in case of directed graph.The edge may have a weight or is set to one in
case of unweighted graph.
Consider the given below graph,

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

A complete graph would have n(n-1)/2 edges.

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.

Proof for complete graph:


1. Consider a complete graph with n nodes. Each node is connected to other n-1
nodes. Thus it becomes n * (n-1) edges. But this counts each edge twice because
this is a undirected graph so divide it by 2.
2. Thus it becomes n(n-1)/2.

Consider the given graph,


//Omit the repetitive edges
Edges on node A = (A,B),(A,C),(A,E),(A,C).
Edges on node B = (B,C),(B,D),(B,E).
Edges on node C = (C,D),(C,E).
Edges on node D = (D,E).
Edges on node E = EMPTY.https://en.wikipedia.org/wiki/Graph_theory
Total edges = 4+3+2+1+0=10 edges.
Number of node = 5.
Thus n(n-1)/2=10 edges.
Thus proven.

Graph Theory Basics – Set 2

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. 

The handshaking theorem, for undirected graphs, has an interesting result – 


 
Theorem 1 shows that the sum of the degrees of the vertices of an
undirected graph is even. This simple fact has many consequences, one
of which is given as Theorem 2.

THEOREM 2 An undirected graph has an even number of vertices of odd degree.


Some special Simple Graphs :

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.

REMOVING OR ADDING EDGES OF A GRAPH

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

Similarly, if E′ is a subset of E, we can produce a subgraph of G by removing the edges in E′


from the graph. The resulting subgraph has the same vertex set V as G. Its edge set is 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}.

REMOVING VERTICES FROM A GRAPH

When we remove a vertex v and all edges incident to it from G = (V, E), we produce a
subgraph, denoted by G − v.

Observe that G − v = (V − {v}, E′ ), where E′ is the set of edges of G not incident to v.

Similarly, if V′ is a subset of V, then the graph G − V′ is the subgraph (V − V′ , E′ ), where E′ is


the set of edges of G not incident to a vertex in 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)

Explanation: Background required – Basic Combinatorics


Since the given graph is undirected, that means the order of edges doesn’t matter.
Since we have to insert an edge between all possible pair of vertices, therefore
problem reduces to finding the count of the number of subsets of size 2 chosen from
the set of vertices.
Since the set of vertices has size n, the number of such subsets is given by the
binomial coefficient C(n,2) (also known as “n choose 2”). Using the formula for
binomial coefficients, C(n,2) = n(n-1)/2.
C(n,k)= n!/k!(n-k)!=n!/2!(n-2)!=n(n-1)(n-2)!/2*1*(n-2)!=n(n-1)/2
2.
What is the number of vertices in an undirected connected graph with 27 edges, 6
vertices of degree 2, 3 vertices of degree 4 and remaining of degree 3?
(A) 10
(B) 11
(C) 18
(D) 19

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

6*2 + 3*4 + (x-9)*3 = 27*2


24 + (x-9)*3 = 54

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)

Explanation: P is true for undirected graph as adding an edge always increases


degree of two vertices by 1.
Q is true: If we consider sum of degrees and subtract all even degrees, we get an even
number because every edge increases the sum of degrees by 2. So total number of odd
degree vertices must be even.

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

The number of edges in this graph?


Number of edges is equal to number of pairs of vertices that satisfy
above conditions. For example, vertex pair {(1, 1), (1, 2)} satisfy
above condition.

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.

For vertices with 1, total edges = (Edges where 1 is first part) +


(Edges where 1 is second part and not first part)

= (3 + 5*10 + 3) + (5*10) edges

Same is count for vertices with 12

Total number of edges:


= 800 + [(3 + 5*10 + 3) + 5*10] + [(3 + 5*10 + 3) + 5*10]
= 800 + 106 + 106
= 1012

Since graph is undirected, two edges from v1 to v2 and v2 to v1


should be counted as one.

So total number of undirected edges = 1012/2 = 506.

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.

6. The maximum number of edges in a bipartite graph on 12 vertices is:


(A) 36
(B) 48
(C) 12
(D) 24

12 vertices; se é bipartido então há 6 vertices em cada subset (de partida e de


chegada); os vertices em cada subset não se contactam; logo cada 6 vertices do
subconjunto partida está ligado no maximo a todos os 6 vertices do
subconjunto de chegada:
V1 liga-se a 6 vertices do subconjunto partida
V2 liga-se a 6
V3 liga-se a 6
V4 liga-se a 6
V5 liga-se a 6
V6 liga-se a 6
Ou seja 6*6=36

Answer: (A)

Explanation: Number of edges would be maximum when there are 6 edges on each


side and every vertex is connected to all 6 vertices of the other side.

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)

Explanation: Minimum: The removed vertex itself is a separate connected


component. So removal of a vertex creates k-1 components.
Maximum: It may be possible that the removed vertex disconnects all components.
For example the removed vertex is center of a star. So removal creates n-1
components.

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.

Connected or Disconnected Graph: A graph G is said to be connected if for any pair


of vertices (Vi, Vj) of a graph G are reachable from one another. Or a graph is said to
be connected if there exist atleast one path between each and every pair of vertices in
graph G, otherwise it is disconnected. A null graph with n vertices is disconnected
graph consisting of n components. Each component consist of one vertex and no edge.

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.

A formal definition of walks and related terminology is given in Definition:

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)

Trail is an open walk in which no edge is repeated. 

Vertex can be repeated.

Here 1->3->8->6->3->2 is trail 


Also 1->3->8->6->3->2->1 will be a closed trail 

3. Circuit – CIRCUITO (OU PISTA FECHADA)


Traversing a graph such that not an edge is repeated but vertex can be repeated and it
is closed also i.e. it is a closed trail. 
 
Vertex can be repeated.
Edge can not be repeated. 

Here 1->2->4->3->6->8->3->1 is a circuit.

Circuit is a closed trail.


These can have repeated vertices only.

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

Here 6->8->3->1->2->4 is a Path 


5. Cycle
Traversing a graph such that we do not repeat a vertex nor we repeat a edge but the
starting and ending vertex must be same i.e. we can repeat starting and ending
vertex only then we get a cycle. 

Vertex not repeated 


Edge not repeated 
Starting and ending vertices are the same
 

Here 1->2->4->3->1 is a cycle. 


Cycle is a closed path.
These can not have repeat anything (neither edges nor vertices), except the start and
end vertice

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 Measurements: There are few graph measurement methods available: 


1. Length – 
Length of the graph is defined as the number of edges contained in the graph. 

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. 

Shortest Distance between 1 - 5 is 2


1→2→5

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. 

Euler paths and circuits : 


 An Euler circuit is a circuit (closed trail) that uses every edge of a graph exactly
once.
 An Euler trail is a trail that uses every edge of a graph exactly once.
 An Euler circuit starts and ends at different vertices.
 An Euler starts and ends at the same vertex.(???)
 The Konigsberg bridge problem’s graphical representation : 
 


 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 – 
 

 Example 2- Does the following graph have a Hamiltonian Circuit? 


 

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

=> Euler Graph


Planar Graphs and Graph Coloring

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 –

 Example – Is the hypercube Q 3 planar?

 Solution – Yes, Q3  is planar. Its planar representation-

Regions in Planar Graphs –


The planar representation of a graph splits the plane into regions. These regions are
bounded by the edges except for one region that is unbounded.
For example, consider the following graph ”

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 –

Are the graphs G and G’ the same?


If your answer is no, then you need to rethink it. The graphical arrangement of the
vertices and edges makes them look different, but they are the same graph. Also notice
that the graph G’ is a cycle, specifically C 5.

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

In most graphs checking first three conditions is enough.


If any of these quantities differ in two simple graphs, these graphs cannot be
isomorphic. However, when these invariants are the same, it does not necessarily
mean that the two graphs are isomorphic.

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.

Connectivity of a graph is an important aspect since it measures the resilience of the


graph.
“An undirected graph is said to be connected if there is a path between every pair of
distinct vertices of the graph.”
Connected Component – A connected component of a graph G is a connected
subgraph of G that is not a proper subgraph of another connected subgraph of  G.
For example, in the following diagram, graph G1 is connected and graph G2 is
disconnected. Since G1 is connected there is only one connected component.
But in the case of G2 there are three connected components.

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

Strongly Connected Component –


Analogous to connected components in undirected graphs, a strongly connected
component is a subgraph of a directed graph that is not contained within another
strongly connected component.
Articulation points –
The removal of a vertex and all the edges incident with it may result in a subgraph that
has more connected components than in the original graphs. Such vertices are called
articulation points or cut vertices.
Analogous to cut vertices are cut edge the removal of which results in a subgraph
with more connected components. A cut-edge is also called a bridge.

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.

Paths and Isomorphisms –


Sometimes even though two graphs are not isomorphic, their graph invariants- number
of vertices, number of edges, and degrees of vertices all match. In this case paths and
circuits can help differentiate between the graphs.
 Example – Are the two graphs shown below isomorphic?

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

Which of the following graphs is isomorphic to

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

Explanation: There can be total 6C4 ways to pick 4 vertices from 6. The value


of 6C4 is 15. (6!/4!(6-4)!=6*5*4!/4!2!=30/2=15)
 Note that the given graph is complete, so any 4 vertices can form a cycle.
 There can be 6 different cycle with 4 vertices. For example, consider 4 vertices
as a, b, c and d. The three distinct cycles are
 cycles should be like this
(a, b, c, d,a)
(a, b, d, c,a)
(a, c, b, d,a)
(a, c, d, b,a)
(a, d, b, c,a)
(a, d, c, b,a)
 and
 (a, b, c, d,a) and (a, d, c, b,a)
(a, b, d, c,a) and (a, c, d, b,a)
(a, c, b, d,a) and (a, d, b, c,a)
are same cycles.
 So total number of distinct cycles is (15*3) = 45.

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

A cycle on n vertices is isomorphic to its complement. The value of n is _____.


(A) 2
(B) 4
(C) 6
(D) 5

Answer: (D)

Explanation: Below is a cyclic graph with 5 vertices and its complement graph.

The complement graph is also isomorphic (same number of vertices connected in


same way) to given graph.

A graph is self-complementary if it is isomorphic to its complement. For all self-


complementary graphs on n vertices, n is
(A) A multiple of 4
(B) Even
(C) Odd
(D) Congruent to 0 mod 4, or 1 mod 4

Answer: (D)

Explanation: An n-vertex self-complementary graph has exactly half number of


edges of the complete graph, i.e., n(n − 1)/4 edges, and (if there is more than one
vertex) it must have diameter either 2 or 3. Since n(n −1) must be divisible by 4, n
must be congruent to 0 or 1 mod 4; for instance, a 6-vertex graph cannot be self-
complementary.
In a connected graph, a bridge is an edge whose removal disconnects a graph. Which
one of the following statements is True?
(A) A tree has no bridge
(B) A bridge cannot be part of a simple cycle
(C) Every edge of a clique with size ≥ 3 is a bridge (A clique is any complete
subgraph of a graph)
(D) A graph with bridges cannot have a cycle

Answer: (B)

Explanation: A bridge in a graph  cannot be a part of cycle as removing it will not


create a disconnected graph if there is a cycle.

An edge in an undirected connected graph is a bridge iff removing it disconnects the


graph. For a disconnected undirected graph, definition is similar, a bridge is an edge
removing which increases number of disconnected components. 
Like Articulation Points , bridges represent vulnerabilities in a connected network and
are useful for designing reliable networks. For example, in a wired computer network,
an articulation point indicates the critical computers and a bridge indicates the critical
wires or connections.
Following are some example graphs with bridges highlighted with red color.
How to find all bridges in a given graph? 
A simple approach is to one by one remove all edges and see if removal of an
edge causes disconnected graph. Following are steps of simple approach for
connected graph.
1) For every edge (u, v), do following 
…..a) Remove (u, v) from graph 
..…b) See if the graph remains connected (We can either use BFS or DFS) 
…..c) Add (u, v) back to the graph.
Time complexity of above method is O(E*(V+E)) for a graph represented
using adjacency list.
Matching (graph theory)

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)

In graph theory, betweenness centrality is a measure of centrality in a graph based on


shortest paths. For every pair of vertices in a connected graph, there exists at least one
shortest path between the vertices such that either the number of edges that the path
passes through (for unweighted graphs) or the sum of the weights of the edges (for
weighted graphs) is minimized. The betweenness centrality for each vertex is the
number of these shortest paths that pass through the vertex.
Betweenness centrality finds wide application in network theory: it represents the
degree of which nodes stand between each other. For example, in a
telecommunications network, a node with higher betweenness centrality would have
more control over the network, because more information will pass through that node.
Betweenness centrality was devised as a general measure of centrality: it applies to a
wide range of problems in network theory, including problems related to social
networks, biology, transport and scientific cooperation.
Tree

Binary Tree | Set 1


Trees: Unlike Arrays, Linked Lists, Stack and queues, which are linear data
structures, trees are hierarchical data structures.
Tree Vocabulary: The topmost node is called root of the tree. The elements that are
directly under an element are called its children. The element directly above
something is called its parent. For example, ‘a’ is a child of ‘f’, and ‘f’ is the parent of
‘a’. Finally, elements with no children are called leaves. 

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.

A Binary Tree node contains following parts.


1. Data
2. Pointer to left child
3. Pointer to 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:

Você também pode gostar