• Nenhum resultado encontrado

Definitions & examples

2.2 Graph theory

2.2.2 Definitions & examples

The following section lists some useful definitions on graph theory, taken from Joyneret al.(2011),Wilson(1996) andDiestel(2010). The graph visualizations where created with Wolfram Mathematica.

Types of graphs

Definition 2.1: AgraphG= (V, E)consists of two setsV andE, where the elements ofV are calledverticesornodesand the elements ofE,edges. Each edge is a pair of two vertices inV that are calledendpointsof that edge.

2.2. Graph theory

An example of graph could be an electronic social network where each account is a node, and «friendships» are edges joining the nodes. An instance of such a graph (Figure2.4) could be

G= (V, E)

V ={Gregory, Ralph, Alan, P eter, Hector, Sigurd}

E ={(Gregory, Alan),(Hector, P eter),(P eter, Ralph)}

Figure 2.4 A simple graph

Definition 2.2: A graph can be categorized by the orientation of its edges:

Directed (digraph) The order of the vertices in the edge(x, y)denotes the direction fromx, thehead, toy, thetail. Directed edges are sometimes calledarcsorarrowsand the letterAis used for clarity —G= (V, A).

Undirected: The endpoints are unordered, thus(x, y)≡(y, x).

Mixed Some of its edges are undirected while others di- rected. To distinguish between ordered and un- ordered edges, we usually define as a triple of three sets,G = (V, E, A)whereE andAare the sets of undirected and directed edges respectively.

CHAPTER 2. THEORETICAL BACKGROUND In the previous example, the «friendship» status is represented by an undi- rected graph as it is a mutual property. Though, in such networks, connections are usually formed after the acceptance of friend requests. The graph with the same vertices (people) and edges («friendships») after reordering the endpoints such that the first endpoint denotes the person that sent the request, is a directed graph like the one in Figure2.5.

This way, the extra information for each connection is not separately held in another set (or data structure in computer applications) but in the notion (a single boolean variable) of whether the graph is directed or not.

Figure 2.5 A directed graph (or digraph)

Definition 2.3: A numerical value assigned to a vertex or an edge of a graph is calledweight. A graph can beedge–weightedorvertex–weightedor both.

Note that the term weighted graph without specification of the set that is weighted (vertices or edges) usually refers to edge–weighted graphs. The most common notation is the triple of vertices, edges and weight function: G = (V, E, w)wherew:E →R.

For example, a graph consisting of cities as vertices and roads interconnecting them as edges may be weighted in various manners: driving distance, average time for a company’s trucks to cover the distance, number of telephone booths etc. (Figure2.6.)

2.2. Graph theory

Figure 2.6 A weighted graph of cities where the departments of a company reside, with weights representing the cost in thousands of euros for the establishment of direct communication infrastructure between them.

Definition 2.4: A subgraphG1(V1, E1)ofG2(V2, E2)has a subset of vertices and edges ofG2. A supergraphG3(V3, E3)ofG2 is formed by adding vertices and/or edges toG2:

G1G2V1V2, E1E2 G3G2V3V2, E3E2

Structure

Definition 2.5: Thedegreeof a node (vertex) is the number of edges it partici- pates in as endpoint, or equivalently the number of nodes it is connected to. In a directed graph, thein–degreeof a node is the number of arrows pointing to the vertex, while theout–degreeis the number of arrows pointing from it.

Definition 2.6: Apathorwalkis an alternating sequence of vertices and edges that starts and ends with a vertex such that the vertices adjacent to an edge in the sequence are endpoints of the latter. In a directed or mixed graph the order of the vertices in the sequence ought to be consistent with the direction of the

Note for Greek speaking readers: supergraph can be translated asυπεργράφος which can be mistaken forhypergraph. Hypergraphs is a generalization of graphs where the edges connected more than two nodes.

CHAPTER 2. THEORETICAL BACKGROUND adjacent edges.

In the weighted graph of Figure2.6, a possible path could be Athens,(Athens,Talin), T alin,(Talin,Paris),Paris

Definition 2.7: A cycleor aclosed walkis a path where the starting vertex is also the ending vertex with no repetition of edges. Graphs can becyclicor acyclicdepending on whether they contain cycles or not respectively.

For the undirected graphG(cities,roads), a path may be the sequence of cities and roads visited by a car. If the driver ended up in the same city, it’s path is a cycle. In the weighted graph of Figure2.6, a cycle could be

Athens,(Athens,Talin),Talin,(Talin,Paris),Paris,(Paris,Athens),Athens Furthermore, if we only care about the distinct cities or roads that the driver saw, we can define a new subgraph containing only those vertices and edges.

This subgraph may be cyclic if the driver arrived at at least one city using more than one road (returning to a city from the same road does not require a new edge as the graph is undirected.)

Connectivity and completeness

Definition 2.8: A graph isconnectedif there is a path connecting each vertex with any other vertex in V. A disconnected graph has at least one pair of vertices for which there is no path connecting them.

The graph in Figure 2.4 is disconnected, while the one in Figure 2.6 is connected. Buildings or other structures as vertices and roads as edges can form a graph representation of a city. Even if buildings are usually not directly connected to each other, there is a way to reach any of them starting from any other. Building a huge wall in the middle would disconnect the graph.

in MoravaPack, we use a class calledDisconnectedGraphwith the meaning that there are no edges at all, aiming to the simplification of the programming process and to the separation of function operating on vertices alone.

2.2. Graph theory

Definition 2.9: An empty or null graph is the graph for which E (and V depending on the source or context) is the empty set. The other extreme case is thecomplete graphwhere the edges join all vertices to each other.

If the vertices of a graph are N people in a meeting and the edges denote handshakes, then a civilized gathering would start with a complete graph having

N(N−1)

2 edges. For example, the handshakes of the members of the social network in Figure2.4could be presented by the graph in Figure2.7.

Figure 2.7 A complete graph: all possible edges are in the graph.

Trees and forests

Definition 2.10: Atree, usually denoted asT, is an undirected graph that is connected and acyclic.

The classical view of the «phylogenetic tree of life» consists of all the species that ever lived on earth (vertices) and connects ancestors to descendants (edges.) It is also a tree in terms of graph theory by being

• connected: there is a common ancestor

• acyclic: each species has exactly one ancestor

CHAPTER 2. THEORETICAL BACKGROUND Though, recent advances in biology discovered mechanisms for transferring genetic information between unrelated organisms (horizontal gene transfer), re- ject the concept of a common ancestor (Doolittle,1999) and propose a «connected cyclic graph of life» or «net».

Definition 2.11: For a given graphG(V, E), a subgraphG0(V, E0)is called spanningwhen it contains all the vertices ofG:V0 =V.

Definition 2.12: Aspanning treeT(V, E0)of an undirected graphG(V, E)is a spanning graph of the latter which is also a tree.

Note that the spanning tree does not have to be a subgraph of the graph it spans, as it may contain edges not found in the latter.

For example, the graph in Figure2.8is

• a tree (being connected and acyclic graph),

• a subgraph of the graph in Figure2.7, and

• both a spanning graph and a spanning tree of the graphs in Figures2.4 and2.7

Figure 2.8 A spanning tree

Definition 2.13: For a connected, undirected and weighted graph G(V, E) there can be a number of spanning trees (except for the trivial case of a graph with less than three vertices). At least one of the spanning treesM(V, E0)has

2.2. Graph theory

the minimal total weighting and it is calledminimum weight spanning tree or more commonlyminimum spanning treeofG.

If the weights inE are distinct then there can be only one minimum spanning tree. If this is not the case then there is a set of minimum spanning trees, all sharing the same total weight and set of weights.

The solution of a minimum connector problem is always a minimum spanning tree. In our example with the cities (Figure2.6), we can state such a problem:

If the departments can work as proxies for the communication, which connections should be made so that they are all directly or indirectly connected to each other and the cost of the infrastructure is mini- mized?

In Figure2.9we can see the solution.

Figure 2.9 The minimum spanning tree of the graph in Figure2.6.

Definition 2.14: AforestF is a graph with no cycles.

One can note that it is a synonym of acyclic graph. Though, it is used in the context of trees, as it emphasizes the fact that any acyclic graph can be seen as a union of trees. Even the extreme case of a graph with no edges andnvertices, is a forest containingnone–vertexed trees. Also, a forest that is also a connected graph is necessarily a tree.

The above call for some clarifications:

CHAPTER 2. THEORETICAL BACKGROUND

• In set theory0 , {0}as0is a number and{0}is a set containing0. An inexperienced reader may mistake a forest for a set of trees.

• In graph theory, trees and forests are both graphs. This means that there is no hierarchical relation between them making it possible to be equivalent:

the forest of one tree is the tree itself and not a set of trees containing it. We will see later that Kruskal’s algorithm operates on forests that are subgraphs of a tree.

Definition 2.15: Aspanning forestF(V, E0)of a graphG(V, E)is the forest containing all the vertices ofGand a subset of its edges (E0E) such that a disjoint union of trees is formed (any vertex or edge belongs to only one tree).

If a graph is disconnected, then there is no spanning tree — and consequently no minimum spanning tree — but there can be a set of trees or MSTs, even if some of them contain only one vertex and no edges. For example, the supergraph of a spanning tree and a vertex which is not joined to any other vertices, is a spanning forest.

For a connected graph, there is always a (minimum) spanning tree, which is also a (minimum) spanning forest. However, a disconnected graph can only be associated with a spanning forest. Thus, algorithms applied on undirected graphs which may or may not be connected should always be supported by a data representation of forests or inform the user for the inability to find a spanning tree.

In addition, there are graph theoretic mathematical proofs or algorithms that handle forests in the process of finding trees of MSTs of a given graph (e.g.

Kruskal’s algorithm.)

For example, in Figure 2.10 we can see a forest, which happens to be a subgraph and spanning forest of the tree in Figure2.8and the complete graph in Figure2.7.