Table of Contents
What is Graph Database
Terminology of Graph Data Structure essential for Graph Database
Operation on Graph
Properties of Graphs and Nodes
What Is a Graph?
Graphs data model is based on Graph data structure.
Graph consist of two parts: vertices and edges.
Vertices are sometimes called nodes.
Graph Data Structure
A graph organizes items in an interconnected network.
Each item is a node (or vertex). Nodes are connected (be linked) by edges become network
Directed vs undirected
In directed graphs, edges point from the node at one end to the node at the other end.
In undirected graphs, the edges simply connect the nodes at each end.
Cyclic vs acyclic
A graph is cyclic if it has a cycle.
Graphs without cycles are acyclic.
Weighted or unweighted
If each edge of a graph has a "weight“, it is called weighted graph.
The weight could, for example, represent the distance between two locations, or the cost or time it takes to travel between the locations.
Bipartite Graph
All the vertices of the graph should be divided into two distinct sets of vertices X and Y.
All the vertices present in the set X should only be connected to the vertices present in the set Y with some edges.
That means the vertices present in a set should not be connected to the vertex in the same set.
The graph shown in the image is divided into two vertices named set X and set Y.
The contents of these sets are:
Set X = {vertex A, vertex B, vertex C, vertex D} Set Y = {vertex P, vertex Q, vertex R}
The vertex A of the set X is associated with the vertex Q of the set Y. And the vertex B is also connected to the vertex Q. The vertex C of the set X is connected to the two vertices of the set Y named vertex P and vertex R. The vertex D of the set X is associated with the vertex R of the set Y.
Similarly, all the vertices present in the set Y are only connected to the vertices from the set X.
The graph shown in the above image satisfies all the conditions for the Bipartite graph.
Elements of Graph Database in Details
Vertex
Edge
Path
Loop
Vertex
A vertex can represent virtually any entity that has a relation with another entity.
Vertices can represent
People in a social network
Cities connected by highways
Proteins that interact with other proteins in the body
Warehouses in a company’s distribution network
Vertex with Properties
Vertices can have properties.
For example, a vertex in a social network represents a person.
It has properties name, address, and birth date.
Similarly, a graph of a highway system uses vertices to represent cities.
Cities have a name, populations, a longitude and latitude, and etc.
Edge
An edge, known as a link or arc, defines relationships between vertices.
For example, in a family tree database, vertices can represent people, whereas the edges represent the relationships between them, such as “daughter of” and “father of.”
In a highway database, cities are represented with vertices, edges represent highways linking the cities.
Edge with Properties
Much like vertices, edges also have properties.
For example, in the highway database, all edges will have properties, such as distance, speed limit, and number of lanes.
In the family tree, edges may have properties indicating whether two people are related by marriage, adoption, or biology.
Weighted edges
Weights represent some value about the relationship.
For example, in highways, weight could be the distance between cities.
In a social network, weight could be an indication of how frequently the two individuals post on each other’s walls or comment on each other’s posts.
In general, weights can represent cost, distance, or another measure of the relationship between objects.
Path
A path through a graph is a set of vertices along with the edges between those vertices.
If edges are directed, the path is a directed path.
If the graph is undirected, the paths in it are undirected paths
Paths are important to capture information about how vertices in a graph are related.
In the case of a highway graph, there may be multiple paths between cities.
Loop
A loop is an edge that connects a vertex to itself.
For example, in biology, some proteins interact with other protein molecules of the same type.
Operations on Graphs
Common operations performed on databases include inserting, reading, updating, and deleting data.
You do this in graph databases as well.
Graph databases are also well suited for an additional set of operations, such as operations can be used to follow paths or detect repeating patterns in relationships between vertices.
The following sections cover three important operations unique to graphs:
Union of graphs
Intersection of graphs
Graph traversal
Properties of Graphs and Nodes
Several properties of graphs and nodes are useful when comparing and analyzing graphs.
These include
Isomorphisms
Order and Size
Degree
Closeness
Betweenness