|
1 | | -## Basic definitionsThere is a great set of mathematical problems that can be solved using graph models. Graphs are vastly used in all kind of computer science problems.Graphs are discrete mathematical structures that consist of a set of vertices \(also called nodes\) and a set of edges that connect those vertices.In computer science is more commonly used the term _node_ instead of _vertex_. In this booklet the term node is going to be the one used.There are multiple types of graphs according if the edges are directed or undirected, if the edges are weighted or unweighted and so on.In this chapter, basic graph concepts and graphs types are going to be explained to ease the following of the algorithms.### Type of Graphs#### Directed GraphA directed graph is a type of graph in which every edges has a direction: an ingoing node and an outgoing node. The most commonly way of representing a graph is to draw it.A directed graph can de drawn like in Figure *@directed@*:#### Undirected GraphAn undirected graph is a type of graph in which the edges does not have a direction. They can be drawn without a line that does not have any arrow heads. It isunderstood that the graph has no direction if the direction is not specified explicitly as shown in Figure *@undirected@*.#### Weighted GraphA weighted graph is a graph that each of its edges has an associated weight \(see Figure *@weighted@*\). In real life examples, the weights can represent several things.For example, a graph can be a map in which the nodes represent cities and the edges represent the distance between those cities.#### Connected GraphA connected graph is an undirected graph in which exists a path for every pair of nodes.For example, Figure *@connected@* represents a connected graph because from any node you can get to any node.But, Figure *@directed2@* is a disconnected graph because the nodes F and G are isolated from the rest.### Graph CycleA graph cycle is a sequence of adjacent nodes in which all nodes are different except of the first and the last one.That means, a graph cycle is a path that ends and starts in the same node without repeating any other node and it has a size grater than 3.For example, in Figure *@cycle1@* there is a cycle between nodes _A, B, D_.But, in Figure *@cycle2@* there is no cycle between from node A to C because the node D has to be traveled twice.Nevertheless, there is a cycle between node D, B and C.#### Directed Acyclic Graph \(DAG\)Like the name suggests, a directed acyclic graph is a directed graph that does not have any cycles \(as shown in Figure *@DAG@*\).#### Strongly Connected GraphUnlike the Connected Graph, a Strongly Connect is a **directed** graph in which there is a path for every pair of nodes. Figure *@strongly1@* is a strongly connected graph.Figure *@strongly2@* is not strongly connected because it is not possible to reach node D from node A. However, if the directions of the graph are deleted, the graph becomes a**undirected** connected graph. For that reason, Figure *@strongly2@* is called a weakly connected graph.#### Strongly Connected ComponentA strongly connected component of a directed graph is the maximal subgraph that is strongly connected. In the figure there are three strongly connected components in the graph: $\{A, B, C\}$, $\{F, E\}$, $\{D\}$.### TreeA tree is a connected graph without cycles. That means that there is only one path between every pair of vertices. But, in the computer science context, normally a tree isrepresented as a **directed** graph. In that case, the definition will be that a **directed** tree is a directed acyclic graph in which every node has only oneincoming \(parent\) node \(See Figure *@directedTree@*\). If you remove the direction of the directed acyclic graph the reaming graph has to be an **undirected** tree \(See Figure *@undiTree@*\).### ConclusionThese definitions set the stage for the algorithms that we will now describe.Identifying clearly the kind of graphs an algorithm is applied on is key because the working hypothesesare really important. |
| 1 | +## Basic definitions |
| 2 | + |
| 3 | + |
| 4 | +There is a great set of mathematical problems that can be solved using graph models. Graphs are vastly used in all kind of computer science problems. |
| 5 | +Graphs are discrete mathematical structures that consist of a set of vertices \(also called nodes\) and a set of edges that connect those vertices. |
| 6 | +In computer science is more commonly used the term _node_ instead of _vertex_. In this booklet the term node is going to be the one used. |
| 7 | + |
| 8 | +There are multiple types of graphs according if the edges are directed or undirected, if the edges are weighted or unweighted and so on. |
| 9 | +In this chapter, basic graph concepts and graphs types are going to be explained to ease the following of the algorithms. |
| 10 | + |
| 11 | +### Type of Graphs |
| 12 | + |
| 13 | + |
| 14 | +#### Directed Graph |
| 15 | + |
| 16 | + |
| 17 | +A directed graph is a type of graph in which every edges has a direction: an ingoing node and an outgoing node. The most commonly way of representing a graph is to draw it. |
| 18 | +A directed graph can de drawn like in Figure *@directed@*: |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | +#### Undirected Graph |
| 23 | + |
| 24 | + |
| 25 | +An undirected graph is a type of graph in which the edges does not have a direction. They can be drawn without a line that does not have any arrow heads. It is |
| 26 | +understood that the graph has no direction if the direction is not specified explicitly as shown in Figure *@undirected@*. |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +#### Weighted Graph |
| 31 | + |
| 32 | + |
| 33 | +A weighted graph is a graph that each of its edges has an associated weight \(see Figure *@weighted@*\). In real life examples, the weights can represent several things. |
| 34 | +For example, a graph can be a map in which the nodes represent cities and the edges represent the distance between those cities. |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | +#### Connected Graph |
| 39 | + |
| 40 | + |
| 41 | +A connected graph is an undirected graph in which exists a path for every pair of nodes. |
| 42 | +For example, Figure *@connected@* represents a connected graph because from any node you can get to any node. |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +But, Figure *@directed2@* is a disconnected graph because the nodes F and G are isolated from the rest. |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +#### Bipartite Graph |
| 51 | + |
| 52 | +A bipartite graph is a graph whose set of vertices can be split into two subsets A and B in such a way that each edge of the graph joins a vertex in A and a vertex in B. |
| 53 | +A complete bipartite graph is a bipartite graph in which each vertex in A is joined to each vertex in B by just one edge. |
| 54 | + |
| 55 | + |
| 56 | +### Graph Cycle |
| 57 | + |
| 58 | + |
| 59 | +A graph cycle is a sequence of adjacent nodes in which all nodes are different except of the first and the last one. |
| 60 | +That means, a graph cycle is a path that ends and starts in the same node without repeating any other node and it has a size grater than 3. |
| 61 | + |
| 62 | +For example, in Figure *@cycle1@* there is a cycle between nodes _A, B, D_. |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | +But, in Figure *@cycle2@* there is no cycle between from node A to C because the node D has to be traveled twice. |
| 67 | +Nevertheless, there is a cycle between node D, B and C. |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | +#### Directed Acyclic Graph \(DAG\) |
| 72 | + |
| 73 | + |
| 74 | +Like the name suggests, a directed acyclic graph is a directed graph that does not have any cycles \(as shown in Figure *@DAG@*\). |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | +#### Strongly Connected Graph |
| 79 | + |
| 80 | + |
| 81 | +Unlike the Connected Graph, a Strongly Connect is a **directed** graph in which there is a path for every pair of nodes. Figure *@strongly1@* is a strongly connected graph. |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | +Figure *@strongly2@* is not strongly connected because it is not possible to reach node D from node A. However, if the directions of the graph are deleted, the graph becomes a |
| 86 | +**undirected** connected graph. For that reason, Figure *@strongly2@* is called a weakly connected graph. |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | +#### Strongly Connected Component |
| 91 | + |
| 92 | + |
| 93 | +A strongly connected component of a directed graph is the maximal subgraph that is strongly connected. In the figure there are three strongly connected components in the graph: |
| 94 | + $\{A, B, C\}$, $\{F, E\}$, $\{D\}$. |
| 95 | + |
| 96 | + |
| 97 | + |
| 98 | +### Tree |
| 99 | + |
| 100 | + |
| 101 | +A tree is a connected graph without cycles. That means that there is only one path between every pair of vertices. But, in the computer science context, normally a tree is |
| 102 | +represented as a **directed** graph. In that case, the definition will be that a **directed** tree is a directed acyclic graph in which every node has only one |
| 103 | +incoming \(parent\) node \(See Figure *@directedTree@*\). If you remove the direction of the directed acyclic graph the reaming graph has to be an **undirected** tree \(See Figure *@undiTree@*\). |
| 104 | + |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | + |
| 109 | +### Conclusion |
| 110 | + |
| 111 | + |
| 112 | +These definitions set the stage for the algorithms that we will now describe. |
| 113 | +Identifying clearly the kind of graphs an algorithm is applied on is key because the working hypotheses |
| 114 | +are really important. |
0 commit comments