Neo4j Fundamentals-Graph Elements
Your work here is done!
VIDEO
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)
Nodes
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
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.
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
1. 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
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.