The Graph Theory in C# (Part 4)

Let's start with the Vertex. Wikipedia defines a vertex as the fundamental unit of a graph. If you read through the article, it expanded on how the vertex is used in a graph instead of actually describing what a vertex is and what, by itself, a vertex represents. I needed a definition that's less wordy and more specifically focused on the vertex itself. In some other illustrations, the vertex is described as a junction or a region. Again, these are vague. It seemed like the vertex cannot be defined without separating how a graph can be visualized.

In the end, I settled with WolframAlpha's definition of a graph vertex:
"Vertex" is a synonym for a node of a graph... one of the points on which the graph is defined...
Let's observe what jargons are being used here: unit, node, point, junction and region. All vague and conceptual. If a vertex can't be something specific, then all of these suggest that a vertex could be anything! Any object can be a vertex. Any value can be a vertex. Any piece of data/information can be a vertex.

When data/information is stored for digital consumption, it is key to be able to find and identify each of them. For example, two persons named John Smith are still two individuals. Thus, the first John Smith can have a different SSN and the other John Smith his own SSN. Suffice to say, at the very least, there must be an identifier that can be used to uniquely distinguish them.

All of these thought processes led me to conclude that I can define a Vertex as follows

public class Vertex
{
    public int ID { get; set; }
    public object Value { get; set; }
}

This code defines a class Vertex with properties ID and Value. The ID gives the Value an identity. Observe that the Value's type is an "object", which in C# means it can be anything.

In my thought process, a Value must have an ID. Thus, a Vertex instance should have both ID and Value filled or set. This raised a problem for me, because, well... let's be real: not everything has an ID!

The original problem I had that started this quest was because of a set of thousands of interconnected objects that my team and I needed to analyze. Specifically, we had thousands of object names. Names! Just names! They were all unique names, but that was it. None of them had an "ID" per se. I could probably assign them IDs using Excel. Or, maybe I can just let my Vertex be smart enough to assign an ID.

Now hold on a minute, buster! The definition doesn't say anything about the vertex being capable of assigning an ID to itself, right? Well, yes, that's true. However, a vertex needs to be distinct. If there is no ID assigned to the Value, the Vertex needs to make sure that it can be identified uniquely. The analogy I use for this is your DNA, which acted on its own to create the unique you. In the same way, my Vertex needs to have a "DNA" that will make sure the Value can be distinguished from another Vertex.Value even if the values seem the same (remember the two John Smiths?). That same "DNA" must also act like a universal counter for all Vertex instances created by an application's run/session with my graph library.

Now how in the world would I do that?

Comments