Graph Elements

Graph elements

Let’s take a closer look at the two elements that make up a graph:

  • Nodes (also known as vertices)

  • Relationships (also known as edges)

A diagram representing nodes and relationships

Nodes

Two nodes representing Michael and Sarah

Nodes (or vertices) are the circles in a graph. Nodes commonly represent objects, entities, or merely things.

In the Seven Bridges of Königsberg example in the previous lesson, nodes were used to represent the land masses.

Another example that everyone can relate to is the concept of a social graph. People interact with each other and form relationships of varying strengths.

The diagram to the right has two nodes which represent two people, Michael and Sarah. On their own, these elements are uninspiring. But when we start to connect these circles together, things start to get interesting.

Nodes typically represent things

Examples of entities that could typically be represented as a node are: person, product, event, book or subway station.

Relationships

Two nodes representing Michael and Sarah and connected by a MARRIED_TO relationship

Relationships (or edges) are used to connect nodes. We can use relationships to describe how nodes are connected to each other. For example Michael has the WORKS_AT relationship to Graph Inc because he works there. Michael has the MARRIED_TO relationship to Sarah because he is married to her.

All of a sudden, we know that we are looking at the beginnings of some sort of social graph.

Now, let’s introduce a third person, Hans, to our Graph.

Three nodes representing Michael

Hans also works for Graph Inc along with Michael. Depending on the size of the company and the properties of the relationship, we may be able to infer that Michael and Hans know each other.

If that is the case, how likely is it that Sarah and Hans know each other?

These are all questions that can be answered using a graph.

Relationships are typically verbs.

We could use a relationship to represent a personal or professional connection (Person knows Person, Person married to Person), to state a fact (Person lives in Location, Person owns Car, Person rated Movie), or even to represent a hierarchy (Parent parent of Child, Software depends on Library).

Check your understanding

Nodes or relationships?

Say we wanted to add additional data to our graph to detail that Michael lives in London, which element would best represent that location?

  • ✓ Node

  • ❏ Relationship

Hint

A location is an entity in our graph.

Solution

We would use nodes to represent a location, and use a relationship to represent the connection between Michael and London.

Summary

In this lesson you learned about nodes (vertices) and relationships (edges) that make up a graph. Next, you will learn about graph structure where relationships may have direction or weights.

Chatbot

Hi, I am an Educational Learning Assistant for Intelligent Network Exploration. You can call me E.L.A.I.N.E.

How can I help you today?