Skip to content

Commit 6d6170f

Browse files
authored
Chapter 2 revised.
1 parent 0122655 commit 6d6170f

File tree

1 file changed

+97
-114
lines changed

1 file changed

+97
-114
lines changed

Chapters/Chapter2/chapter2.md

Lines changed: 97 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,97 @@
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-
![A directed graph.](figures/directed_graph.pdf width=30&label=directed)
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-
![An undirected graph.](figures/undirected_graph.pdf width=30&label=undirected)
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-
![A weighted graph: edges have a weight.](figures/weighted_graph.pdf width=40&label=weighted)
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-
![A connected graph: all the nodes are reachable from any others.](figures/connected_graph.pdf width=40&label=connected)
45-
46-
But, Figure *@directed2@* is a disconnected graph because the nodes F and G are isolated from the rest.
47-
48-
![A disconnected graph: some nodes are not reachable from others.](figures/disconnected_graph.pdf width=48&label=directed2)
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-
![A Cycle in a graph.](figures/cycle_in_a_graph.pdf width=40&label=cycle1)
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-
![In a directed graph, direction is impacting cycle presence. ](figures/not_a_cycle.pdf width=52&label=cycle2)
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-
![A directed Acyclic Graph.](figures/dag.pdf width=35&label=DAG)
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-
![A strongly connected graph.](figures/strongly_connected_graph.pdf width=30&label=strongly1)
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-
![A weakly connected graph.](figures/not_strongly_connected_graph.pdf width=30&label=strongly2)
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-
![Graph with three strongly connected components](figures/strongly_connected_components.pdf width=50)
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-
![A tree: a connected graph without cycles.](figures/tree.pdf width=40&label=undiTree)
106-
107-
![A directed tree.](figures/directed_tree.pdf width=40&label=directedTree)
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.
1+
## Basic Definitions
2+
3+
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.
4+
Graphs are discrete mathematical structures that consist of a set of vertices \(also called nodes\) and a set of edges that connect those vertices.
5+
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.
6+
7+
There are multiple types of graphs according if the edges are directed or undirected, if the edges are weighted or unweighted and so on.
8+
In this chapter, basic graph concepts and graphs types are going to be explained to ease the following of the algorithms.
9+
10+
### Type of Graphs
11+
12+
#### Directed Graph
13+
14+
A directed graph (a *digraph*, for short) 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 be drawn like in Figure *@directed@*.
15+
16+
![A directed graph.](figures/directed_graph.pdf width=30&label=directed)
17+
18+
#### Undirected Graph
19+
20+
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 understood that the graph has no direction if the direction is not specified explicitly as shown in Figure *@undirected@*.
21+
22+
![An undirected graph.](figures/undirected_graph.pdf width=30&label=undirected)
23+
24+
#### Weighted Graph
25+
26+
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.
27+
For example, a graph can be a map in which the nodes represent cities and the edges represent the distance between those cities.
28+
29+
![A weighted graph: edges have a weight.](figures/weighted_graph.pdf width=40&label=weighted)
30+
31+
#### Connected Graph
32+
33+
A connected graph is an undirected graph in which exists a path for every pair of nodes.
34+
For example, Figure *@connected@* represents a connected graph because from any node you can get to any node.
35+
36+
![A connected graph: all the nodes are reachable from any others.](figures/connected_graph.pdf width=40&label=connected)
37+
38+
But, Figure *@directed2@* is a disconnected graph because the nodes F and G are isolated from the rest.
39+
40+
![A disconnected graph: some nodes are not reachable from others.](figures/disconnected_graph.pdf width=48&label=directed2)
41+
42+
#### Bipartite Graph
43+
44+
A bipartite graph is a graph whose set of nodes can be split into two subsets $A$ and $B$ in such a way that each edge of the graph joins a node in $A$ and a node in $B$. In Figure @bipartite@, the two subsets are $\{A1, A2, A3, A4, A5\}$ and $\{B1, B2, B3, B4\}$.
45+
A *complete* bipartite graph is a bipartite graph in which each node in A is joined to each node in B by just one edge.
46+
47+
![A bipartite graph: the nodes are split into two subsets.](figures/bipartite.png width=48&label=bipartite)
48+
49+
### Graph Cycle
50+
51+
A 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 greater than 3.
52+
53+
For example, in Figure *@cycle1@* there is a cycle between nodes _A, B, D_.
54+
55+
![A cycle in a graph.](figures/cycle_in_a_graph.pdf width=40&label=cycle1)
56+
57+
But in Figure *@cycle2@*, there is no cycle from node A to C because the node D has to be traveled twice. Nevertheless, there is a cycle between nodes D, B and C.
58+
59+
![In a directed graph, direction is impacting cycle presence.](figures/not_a_cycle.pdf width=52&label=cycle2)
60+
61+
#### Directed Acyclic Graph \(DAG\)
62+
63+
Like the name suggests, a directed acyclic graph is a directed graph that does not have any cycles \(as shown in Figure *@DAG@*\).
64+
65+
![A Directed Acyclic Graph (DAG).](figures/dag.pdf width=35&label=DAG)
66+
67+
#### Strongly Connected Graph
68+
69+
Unlike the connected graph, a strongly connected graph is a **directed** graph in which there is a path for every pair of nodes. Figure *@strongly1@* is a strongly connected graph.
70+
71+
![A strongly connected graph.](figures/strongly_connected_graph.pdf width=30&label=strongly1)
72+
73+
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 an **undirected** connected graph. For that reason, Figure *@strongly2@* is called a weakly connected graph.
74+
75+
![A weakly connected graph.](figures/not_strongly_connected_graph.pdf width=30&label=strongly2)
76+
77+
#### Strongly Connected Component
78+
79+
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:
80+
$\{A, B, C\}$, $\{F, E\}$, $\{D\}$.
81+
82+
![Graph with three strongly connected components](figures/strongly_connected_components.pdf width=50)
83+
84+
### Tree
85+
86+
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
87+
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 incoming \(parent\) node \(See Figure *@directedTree@*\). If you remove the direction of the directed acyclic graph, the remaining graph has to be an **undirected** tree \(See Figure *@undiTree@*\).
88+
89+
![A tree: a connected graph without cycles.](figures/tree.pdf width=40&label=undiTree)
90+
91+
![A directed tree.](figures/directed_tree.pdf width=40&label=directedTree)
92+
93+
### Conclusion
94+
95+
These definitions set the stage for the algorithms that we will now describe.
96+
Identifying clearly the kind of graphs an algorithm is applied on is key because the working hypotheses
97+
are really important.

0 commit comments

Comments
 (0)