Graphs #1
First couple of weeks I have been focused on Pharo. Its syntax, environment and connections. Which has been very helpful, for the implementation part of my project.
Now it is time to switch to other big part, and that is Graphs. Since they are central structure on which my whole project stands on, it is important to have a good understanding of them.
Let us begin with some basic questions.
What is a graph?
Definition: A graph is a set of vertices and a collection of edges that each connect a pair of vertices. 1
Mathematical notation is:
G= (V, E)
Where G is graph, V is set of vertices (nodes) and E is set of edges.
We recognize three types of Graphs:
- Undirected (edges have no direction)
- Directed (it matters from which vertex, edge starts; we call these edges arcs)
- Weighted (each edge has a weight value)
Why graphs?
There are so many uses for graphs: in mathematics, engineering, programming… To answer this question generally it would be too complex. But why did I choose them is much easier.
One of the uses for graphs is representing a network of roads between cities (each city is a vertex, every road connection is edge). This way we can see who can travel where. As I spend some time in researching code refactoring, I thought it would be interesting to see the program code the same way. Classes as vertices and edges as calls. We can follow dependencies easier. Also see which information can travel where.
-
Definition taken from Algorithms, Fourth edition by Robert Sedgewick and Kevin Wayne; page 518. ↩