19 Graph Algorithms You Can Use Right Now
Tags: memgraph, graphdatabase, database, graphalgorithms
Published: 2022-12-16 09:15:48

The fastest to run any graph algorithm on your data is by using Memgraph and MAGE. It’s super easy. [Download Memgraph](https://memgraph.com/download?utm_source=devto&utm_medium=referral&utm_campaign=blog_repost), import your data, pick one of the most popular graph algorithms, and start crunching the numbers.

**Memgraph** is an in-memory graph database. You can use it to traverse networks and run sophisticated graph algorithms out-of-the-box.

**MAGE** is an open-source repository tool supported by Memgraph. MAGE carries different modules and graph algorithms in the form of query modules. 

You can choose from 19 graph algorithms along with their GitHub repositories for your query modules. You can use these algorithms with Memgraph and Mage immediately. 

## Algorithms List

Here is the list of 19 algorithms that we support. You can use these algorithms immediately with Memgraph (graph DB) and Mage (graph library). 

### 1. Betweenness Centrality

Centrality analysis provides information about the node’s importance for an information flow or connectivity of the network. [Betweenness centrality](https://en.wikipedia.org/wiki/Betweenness_centrality) is one of the most used centrality metrics. Betweenness centrality measures the extent to which a node lies on paths between other nodes in the graph. Thus, nodes with high betweenness may have considerable influence within a network under their control over information passing between others. The calculation of betweenness centrality is not standardized, and there are many ways to solve it.

It is defined as the number of shortest paths in the graph that passes through the node divided by the total number of shortest paths. The implemented algorithm is described in the paper "[A Faster Algorithm for Betweenness Centrality](http://snap.stanford.edu/class/cs224w-readings/brandes01centrality.pdf)" by Ulrik Brandes of the [University of Konstanz](https://www.uni-konstanz.de/en/).

![memgraph-betweeness-centrality](https://public-assets.memgraph.com/19-graph-algorithms-that-you-can-use-right-now/memgraph-graph-algorithms-image8.png)

A larger circle means larger betweenness centrality. The middle one has the largest amount of shortest paths flowing through it.

[Implementation Link](https://memgraph.com/docs/mage/algorithms/traditional-graph-analytics/betweenness-centrality-algorithm?utm_source=devto&utm_medium=referral&utm_campaign=blog_repost#implementation)

### 2. Biconnected Components

[Biconnected components](https://en.wikipedia.org/wiki/Biconnected_component) are parts of the graph important in the initial analysis. Finding biconnected components means finding a maximal biconnected subgraph. Subgraph is biconnected if:
* It is possible to go from each node to another within a biconnected subgraph
* The first scenario remains true even after removing any vertex in the subgraph

The problem was solved by [John Hopcroft](https://en.wikipedia.org/wiki/John_Hopcroft) and [Robert Tarjan](https://en.wikipedia.org/wiki/Robert_Tarjan) with linear time complexity. Depending on the use case, biconnected components may help to discover hidden structures within the graph.

![memgraph-biconnected-components](https://public-assets.memgraph.com/19-graph-algorithms-that-you-can-use-right-now/memgraph-graph-algorithms-image20.png)

Different colors are different components. Multi-colored vertices are articulation points.

[Implementation Link](https://memgraph.com/docs/mage/algorithms/traditional-graph-analytics/biconnected-components-algorithm?utm_source=devto&utm_medium=referral&utm_campaign=blog_repost#implementation)

### 3. Bipartite Matching

A bipartite graph is a graph in which we can divide vertices into two independent sets, such that every edge connects vertices between these sets. No connection can be established within the set.

Matching in bipartite graphs (bipartite matching) is described as a set of edges that are picked in a way to not share an endpoint. Furthermore, maximum matching is such matching of maximum cardinality of the chosen edge set. The algorithm runs in O(|V|*|E|) time, where V represents a set of nodes and E represents a set of edges.

This little tool can become extremely handful when calculating assignments between entities. Assigning stuff between two sets of entities is done in a large number of industries, and therefore having a method to find it can make the developing process easier.

![memgraph-bipartite-matching](https://public-assets.memgraph.com/19-graph-algorithms-that-you-can-use-right-now/memgraph-graph-algorithms-image3.png)

[Implementation Link](https://memgraph.com/docs/mage/algorithms/traditional-graph-analytics/bipartite-matching-algorithm?utm_source=devto&utm_medium=referral&utm_campaign=blog_repost#implementation)

### 4. Bridge Detection

As in the real world, the definition of a bridge in graph theory denotes something that divides an entity into multiple components. Thus, more precisely, the [bridge](https://en.wikipedia.org/wiki/Bridge_(graph_theory)) in graph theory denotes an edge that, when removed, divides the graph into two separate components.

![memgraph-bridge-detection](https://public-assets.memgraph.com/19-graph-algorithms-that-you-can-use-right-now/memgraph-graph-algorithms-image9.png)

Example of bridges on the graph. Bold edges represent bridges.

[Implementation Link](https://memgraph.com/docs/mage/algorithms/traditional-graph-analytics/bridges-algorithm?utm_source=devto&utm_medium=referral&utm_campaign=blog_repost#implementation)

### 5. Community Detection

The notion of community in a graph represents similarly to what it represents in the real world. Different social circles are examples of such communities. Analogously, in graphs, community represents a partition of a graph, ie a set of nodes. [M. Girvan](https://scholar.google.com/citations?user=npKBI-oAAAAJ&hl=en) and [M. E. J. Newman](http://www-personal.umich.edu/~mejn/) argue that nodes are more strongly connected within a community, i.e. there are more edges, while on the other hand, nodes are sparsely connected between communities themselves.

There are more potential candidates to address community detection. Among the more popular algorithms are:

1. [Louvain community detection](https://en.wikipedia.org/wiki/Louvain_method) - based on modularity optimization - measures network connectivity within a community
2. [Leiden community detection](https://www.nature.com/articles/s41598-019-41695-z) - adjustment of Louvain's algorithm that introduces one level of refinement and brings together strongly connected communities
3. [Label propagation](https://en.wikipedia.org/wiki/Label_propagation_algorithm) - a machine learning technique that assigns labels to unmarked nodes and modifies them with respect to neighbors

![memgraph-community-detection](https://public-assets.memgraph.com/19-graph-algorithms-that-you-can-use-right-now/memgraph-graph-algorithms-image16.png)

Community detection labels each node with a community label. Here, labels are colored in different colors.

[Implementation Link](https://memgraph.com/docs/mage/algorithms/traditional-graph-analytics/community-detection-algorithm?utm_source=devto&utm_medium=referral&utm_campaign=blog_repost#implementation)

### 6. Cycle Detection

In graph theory, a cycle represents a path within the graph where only starting and ending nodes are similar. Furthermore, cycles can be double-connected links between neighboring nodes or self-loops.

The simplest concept of a solution for finding a cycle was defined by [Robert W. Floyd](https://en.wikipedia.org/wiki/Robert_W._Floyd) in his [tortoise and hare algorithm](https://en.wikipedia.org/wiki/Cycle_detection#Floyd's_tortoise_and_hare), where a hare moves at twice the speed of a tortoise and thus encounters it if there is a cycle. There are many implementations of cycle detection, and among them, the fastest is Professor [Donald B. Johnson](https://en.wikipedia.org/wiki/Donald_B._Johnson) from the Pennsylvania State University - [Finding all the elementary circuits of a directed graph](https://www.cs.tufts.edu/comp/150GA/homeworks/hw1/Johnson%2075.PDF). 

Cycles are not only popular in graph structures but also play an important role in number theory and cryptography. Nevertheless, graph theory concepts are used in other disciplines, and cycle detection is placed as an extremely important tool in initial graph analysis.

![memgraph-cycle-detection](https://public-assets.memgraph.com/19-graph-algorithms-that-you-can-use-right-now/memgraph-graph-algorithms-image17.png)

There are two cycles in the graph from the examples, each colored differently.

[Implementation Link](https://memgraph.com/docs/mage/algorithms/traditional-graph-analytics/cycle-detection-algorithm?utm_source=devto&utm_medium=referral&utm_campaign=blog_repost#implementation)

### 7. Graph Coloring

Certain applications require the special labeling of a graph called [graph coloring](https://en.wikipedia.org/wiki/Graph_coloring). This “special” labeling refers to the assignment of labels (which we call colors) in such a way that connected neighbors must not be given the same color. Since this problem is [NP-hard](https://en.wikipedia.org/wiki/NP-hardness), there doesn't exist an algorithm that can solve the problem in a polynomial time. Therefore, various computer science techniques called [heuristics](https://en.wikipedia.org/wiki/Heuristic_(computer_science)) are used to solve graph coloring.

Of course, the main part of the problem is in assigning a minimum number of labels. There are greedy algorithms that solve the problem, however not optimal. Using dynamic programming, the fastest algorithm guarantees O(2.44 ^ n) complexity. While on the other hand, there are heuristic applications like the one with [genetic algorithms](https://en.wikipedia.org/wiki/Genetic_algorithm).

![memgraph-graph-coloring](https://public-assets.memgraph.com/19-graph-algorithms-that-you-can-use-right-now/memgraph-graph-algorithms-image5.png)

Example of graph coloring on a simple graph. Labels are denoted with different colors.

[Implementation Link](https://memgraph.com/docs/mage/algorithms/traditional-graph-analytics/graph-coloring-algorithm?utm_source=devto&utm_medium=referral&utm_campaign=blog_repost#implementation)

### 8. Node Similarity

The notion of [similarity](https://en.wikipedia.org/wiki/Similarity_(network_science)) can be described in several different ways, but within graph theory, it encompasses several generally accepted definitions. The similarity of graph nodes is based on a comparison of adjacent nodes or the neighborhood structure. These are traditional definitions that take into account only the layout of the graph. If we extend the definition of a node with additional properties, then it is possible to define comparisons based on these properties as well, but this is not the topic of the methods mentioned here.

The result of this type of algorithm is always a pair of nodes and an assigned value indicating the match measure between them. We will mention only the most popular measures based on neighborhood nodes with their brief explanations.

* [Cosine similarity](https://en.wikipedia.org/wiki/Cosine_similarity) - the cosine of the angle by which the product is defined as the cardinality of the common neighbors of the two nodes, and the denominator is the root of the product of the node degrees
* [Jaccard similarity](https://en.wikipedia.org/wiki/Jaccard_index) - a frequently used measure in different models of computer science includes the ratio of the number of common neighbors through the total
* [Overlap similarity](https://developer.nvidia.com/blog/similarity-in-graphs-jaccard-versus-the-overlap-coefficient-2/) - defined as the ratio of the cross-section of a neighborhood to the less than the number of neighbors of two nodes. Overlap similarity works best in the case of a small number of adjacent nodes


![memgraph-node-similarity](https://public-assets.memgraph.com/19-graph-algorithms-that-you-can-use-right-now/memgraph-graph-algorithms-image15.png)

Example of a graph where nodes share a neighborhood. This information is used to calculate similarity.

[Implementation Link](https://memgraph.com/docs/mage/algorithms/traditional-graph-analytics/node-similarity-algorithm?utm_source=devto&utm_medium=referral&utm_campaign=blog_repost#implementation)

### 9. PageRank

In the domain of centrality measurements, [PageRank](https://en.wikipedia.org/wiki/PageRank) is arguably the most popular tool. Today, the most popular search engine in the world, [Google](https://en.wikipedia.org/wiki/Google#Early_years), owes its popularity solely to this algorithm, developed in the early days by its founders.

If we present nodes as pages and directed edges between them as links, the PageRank algorithm outputs a probability distribution used to represent the likelihood that a person randomly clicking on links will arrive at any particular page.

PageRank can be used as a measure of influence that can be used on a variety of applications, not just on website rankings. A popular type of PageRank is [Personalized PageRank](https://dl.acm.org/doi/10.1145/2488388.2488433), which is extremely useful in recommendation systems.

![memgraph-PageRank](https://public-assets.memgraph.com/19-graph-algorithms-that-you-can-use-right-now/memgraph-graph-algorithms-image14.png)

PageRank on a simple network. The biggest vertex points to an adjacent vertex and therefore making it more important.

[Implementation Link](https://memgraph.com/docs/mage/algorithms/traditional-graph-analytics/pagerank-algorithm?utm_source=devto&utm_medium=referral&utm_campaign=blog_repost#implementation)

### 10. Union Find

This is yet another important graph analytics algorithm. By using a [disjoint-set](https://en.wikipedia.org/wiki/Disjoint-set_data_structure) - a data structure that keeps track of non-overlapping sets, the algorithm enables the user to quickly check whether a pair of given nodes are in the same or different connected components. The benefit of having this structure is that a check on a pair of nodes is effectively executed in O(1) time.

The implementation of the disjoint-set data structure and its operations uses the union by rank and path splitting optimizations described in "Worst-case Analysis of Set Union Algorithms", developed by [Robert Tarjan](https://en.wikipedia.org/wiki/Robert_Tarjan) and [Jan van Leeuwen](https://en.wikipedia.org/wiki/Jan_van_Leeuwen).

![memgraph-union-find](https://public-assets.memgraph.com/19-graph-algorithms-that-you-can-use-right-now/memgraph-graph-algorithms-image11.png)

Structure of the disjoint set on the right side, and graph example on the left. When checking the components, the algorithm only checks the shallow tree on the left.

[Implementation Link](https://memgraph.com/docs/mage/algorithms/traditional-graph-analytics/union-find-algorithm?utm_source=devto&utm_medium=referral&utm_campaign=blog_repost#implementation)

### 11. Dynamic node2vec

Dynamic Node2Vec is a random walk-based method that creates embeddings for every new node added to the graph. For every new edge, there is a recalculation of probabilities (weights) that are used in walk sampling. A goal of the method is to enforce that the embedding of node v is similar to the embedding of nodes with the ability to reach node v across edges that appeared one before the other.

**Why Dynamic node2vec**

Many methods, like node2vec, DeepWalk, focus on computing the embedding for static graphs which has its qualities but also some big drawbacks.
Networks in practical applications are dynamic and evolve constantly over time. For example, new links are formed (when people make new friends on social networks) and old links can disappear. Moreover, new nodes can be introduced into the graph (e.g., users can join the social network) and create new links to existing nodes.
Naively applying one of the static embedding algorithms leads to unsatisfactory performance due to the following challenges:
* Stability: the embedding of graphs at consecutive time steps can differ substantially even though the graphs do not change much.
* Growing Graphs: All existing approaches assume a fixed number of nodes in learning graph embeddings and thus cannot handle growing graphs.
* Scalability: Learning embeddings independently for each snapshot leads to running time linear in the number of snapshots. As learning a single embedding is computationally expensive, the naive approach does not scale to dynamic networks with many snapshots

Dynamic Node2Vec is created by F.Beres et al in the "Node embeddings in dynamic graphs".

![memgraph-dynamic-node2vec](https://public-assets.memgraph.com/19-graph-algorithms-that-you-can-use-right-now/memgraph-graph-algorithms-image13.png)

[Implementation Link](https://memgraph.com/docs/mage/algorithms/dynamic-graph-analytics/node2vec-online-algorithm#implementation)

### 12. Dynamic PageRank

In the domain of estimating the importance of graph nodes, [PageRank](https://en.wikipedia.org/wiki/PageRank) is arguably the most popular tool. Today, the most popular search engine in the world, [Google](https://en.wikipedia.org/wiki/Google#Early_years), owes its popularity solely to this algorithm, developed in the early days by its founders.

If we present nodes as pages and directed edges between them as links the PageRank algorithm outputs a probability distribution used to represent the likelihood that a person randomly clicking on links will arrive at any particular page.

The need for its dynamic implementation arose at the moment when nodes and edges arrive in a short period of time. A large number of changes would result in either inconsistent information upon arrival or restarting the algorithm over the entire graph each time the graph changes. Since such changes occur frequently, the dynamic implementation allows the previously processed state to be preserved, and new changes are updated in such a way that only the neighborhood of the arriving entity is processed at a constant time. This saves time and allows us to have updated and accurate information about the new values of the PageRank.

There are also some disadvantages of this approach, and that is that such an approach does not guarantee an explicitly correct solution but its approximation. Such a trade-off is common in computer science but allows fast execution and guarantees that at a large scale such an approximation approaches the correct result.

Valuable work explaining how to quickly calculate these values was developed by [Bahmani et. al.](https://scholar.google.com/citations?user=v-hyE4MAAAAJ&hl=en), engineers from [Stanford](http://snap.stanford.edu/) and [Twitter](https://twitter.com/home?lang=en). The paper is worth reading at [Fast Incremental and Personalized PageRank](http://snap.stanford.edu/class/cs224w-readings/bahmani10pagerank.pdf 📖).

![memgraph-dynamic-pageRank](https://public-assets.memgraph.com/19-graph-algorithms-that-you-can-use-right-now/memgraph-graph-algorithms-image12.png)

[Implementation Link](https://memgraph.com/docs/mage/algorithms/dynamic-graph-analytics/pagerank-online-algorithm?utm_source=devto&utm_medium=referral&utm_campaign=blog_repost#implementation)

### 13. Dynamic Community Detection

To address the hidden relations among the nodes in the graph, especially those not connected directly, [community detection](https://en.wikipedia.org/wiki/Community_structure) can provide help. This familiar graph analytics method is being solved in various different ways. However, demand for scale and speed has increased over the years and therefore led to the construction of dynamic community detection algorithms. To leverage the needs for scalability and speed, community detection lends itself well to dynamic operations for two reasons:
* Complexity: algorithms often have high time complexity that scales with the number of nodes in the network
* Locality: community changes tend to be local in scope after partial updates.

Academic research of temporal graphs yielded [LabelRankT: Incremental Community Detection in Dynamic Networks via Label Propagation](https://arxiv.org/abs/1305.2006) (Xie et al.).

![memgraph-dynamic-community-detection](https://public-assets.memgraph.com/19-graph-algorithms-that-you-can-use-right-now/memgraph-graph-algorithms-image10.png)

Illustration of how a dynamic community detection algorithm adapts to local changes

[Implementation Link](https://memgraph.com/docs/mage/algorithms/dynamic-graph-analytics/community-detection-online-algorithm?utm_source=devto&utm_medium=referral&utm_campaign=blog_repost#implementation)

### 14. Graph Neural Networks (GNN)

[Machine learning](https://en.wikipedia.org/wiki/Machine_learning) methods are based on data. Because of everyday encounters with data that are audio, visual, or textual such as images, video, text, and speech - the machine learning methods that study such structures are making tremendous progress today.

Connection-based data can be displayed as graphs. Such structures are much [more complex than images](https://towardsdatascience.com/machine-learning-on-graphs-part-1-9ec3b0bd6abc) and text due to multiple levels of connectivity in the structure itself which is completely irregular and unpredictable. With the development of neural networks organized in the structure of graphs, the field of [graph machine learning](https://arxiv.org/abs/2005.03675) is improving.

Applying the same principle used, for example, in images (convolutions) to graphs would be a mistake. Such principles are based on grid structures, while on graphs of arbitrary sizes, complex topologies, and random connections applying the same strategy would result in a disaster.

All convolutional network graph methods are based on [message propagation](https://en.wikipedia.org/wiki/Belief_propagation). Such messages carry information through a network composed of nodes and edges of the graph, while each node entity carries its computational unit. The task of each node is to process the information and pass it on to the neighbors.

Various possibilities have been developed that enable machine learning with graph neural networks. Starting with the graph of convolutional networks published in “[Spectral Networks and Deep Locally Connected Networks on Graphs](https://arxiv.org/abs/1312.6203)” (Bruna et al, 2014).

Today's most popular models are [GraphSAGE](https://arxiv.org/abs/1706.02216), [Graph Convolutional Networks (GCN)](https://arxiv.org/abs/1609.02907), [Graph Attention Networks (GAT)](https://arxiv.org/abs/1710.10903), and [Temporal Graph Networks (TGN)](https://arxiv.org/abs/2006.10637) - important for dynamic networks.

![memgraph-graph-neural-networks-GNN](https://public-assets.memgraph.com/19-graph-algorithms-that-you-can-use-right-now/memgraph-graph-algorithms-image2.png)

The above network shows the computation graph of message propagation in GNNs.

[Implementation Link](https://memgraph.com/docs/mage/algorithms/machine-learning-graph-analytics/gnn-algorithm?utm_source=devto&utm_medium=referral&utm_campaign=blog_repost#implementation)

### 15. Graph Classification

Let’s look at one useful tool that allows you to analyze a graph as a whole. [Graph classification](https://paperswithcode.com/task/graph-classification) enables this. The structure and arrangement of nodes can reveal some hidden features in a graph.

So, for example, fraudsters who have a common pattern of behavior can be detected by searching that pattern in the graph of their connections.

To make this possible, the main technique is to design features over the structure of the graph itself and then apply a classification algorithm. This can be achieved in several ways:
* [Graphlet features](https://en.wikipedia.org/wiki/Graphlets) - the number of a particular graphlet indicates a single element of the feature vector
* [Weisfeiler-Lehman kernel](https://www.jmlr.org/papers/volume12/shervashidze11a/shervashidze11a.pdf) - color refinement, teaching colors to the neighborhood until convergence is achieved
* Graph Deep Learning - designing a network that can extract a deeper feature depending on the structure of the graph

![memgraph-graph-classification](https://public-assets.memgraph.com/19-graph-algorithms-that-you-can-use-right-now/memgraph-graph-algorithms-image1.png)

Probability of different labels on graph classification for molecular structures

[Implementation Link](https://memgraph.com/docs/mage/algorithms/machine-learning-graph-analytics/graph-classification-algorithm?utm_source=devto&utm_medium=referral&utm_campaign=blog_repost#implementation)

### 16. Link Prediction

[Link prediction](https://www.sciencedirect.com/topics/computer-science/link-prediction) is the process of predicting the probability of connecting the two nodes that were not previously connected in a graph. A wide range of different solutions can be applied to such a problem.

The problem is of great importance in recommendation systems, co-authorship prediction, drug discovery, and many, many more.

Solving methods range from traditional to machine learning-based. Traditional methods are mostly based either on neighborhood similarity. A link between two nodes is more likely to exist if there are many common neighbors. These are:
1. [Jaccard similarity](https://en.wikipedia.org/wiki/Jaccard_index)
2. [Overlap similarity](https://en.wikipedia.org/wiki/Overlap_coefficient)
3. [Adamic-Adar index](https://en.wikipedia.org/wiki/Adamic/Adar_index)

On the other hand, such a prediction can be learned from the node endpoints by looking at similarity metrics. The more similar the nodes are, the greater the likelihood of connectivity between them. [Cosine similarity and Euclidean distance](https://www.baeldung.com/cs/euclidean-distance-vs-cosine-similarity) are one example of such.

Then, there are the most advanced models so far and they are based on [graph embeddings](https://towardsdatascience.com/graph-embeddings-the-summary-cc6075aba007), which serve as features for further classification tasks. Likewise, it is possible to drive graph neural network (GNN) methods for the same task.

![memgraph-link-prediction](https://public-assets.memgraph.com/19-graph-algorithms-that-you-can-use-right-now/memgraph-graph-algorithms-image18.png)

Predicted relationships within the certain community

[Implementation Link](https://memgraph.com/docs/mage/algorithms/machine-learning-graph-analytics/link-prediction-algorithm#implementation)

### 17. Node Classification

Prediction can be done at the node level. The basis of such prediction systems are features extracted from graph entities.

Extracting a feature can be a complicated problem, and it can be based on different graph attributes — node properties, node adjacency, or the structure of the neighborhood.

Traditional methods of extracting knowledge from nodes include measures of [centrality](https://en.wikipedia.org/wiki/Centrality), importance, or feature structure such as [graphlets](https://en.wikipedia.org/wiki/Graphlets).

Somewhat more advanced methods are extracting the [embedding](https://towardsdatascience.com/graph-embeddings-the-summary-cc6075aba007) of individual nodes, and then a prediction algorithm that takes knowledge from the embeddings themselves. The most popular such tool is [Node2Vec](https://memgraph.com/docs/mage/algorithms/machine-learning-graph-analytics/node2vec-algorithm?utm_source=devto&utm_medium=referral&utm_campaign=blog_repost).

However, these methods are only a few. Today's graph machine learning is being developed and among them, we distinguish many different models such as:
1. [GraphSAGE](http://snap.stanford.edu/graphsage/)
2. [DeepWalk](https://towardsdatascience.com/deepwalk-its-behavior-and-how-to-implement-it-b5aac0290a15)
3. [Graph convolutional networks (GCN)](https://towardsdatascience.com/understanding-graph-convolutional-networks-for-node-classification-a2bfdb7aba7b)
4. [Graph Attention Network (GAT)](https://arxiv.org/abs/1710.10903)

and many, many more. This task has become quite popular and is used in many industries where knowledge is stored in the form of a graph structure.

Previously labeled nodes can be used to determine the class of unclassified ones

![memgraph-node-classification](https://public-assets.memgraph.com/19-graph-algorithms-that-you-can-use-right-now/memgraph-graph-algorithms-image21.png)

[Implementation Link](https://memgraph.com/docs/mage/algorithms/machine-learning-graph-analytics/node-classification-algorithm#implementation)

### 18. Node2Vec

[Embedding](https://towardsdatascience.com/node-embeddings-for-beginners-554ab1625d98) methods serve to map graph entities into n-dimensional vectors. The goal of such an approach is to map closely related entities to vectors with a high degree of similarity according to the chosen method of similarity estimation.

[Node2Vec](https://snap.stanford.edu/node2vec/) stands out as the most popular method. It is based on random walks. The point of this method is mapping nodes that are most likely to be within a common random walk to the same place in n-dimensional space. The method was developed by [Aditya Grover](https://aditya-grover.github.io/) and [Jure Leskovec](https://cs.stanford.edu/people/jure/), professors at Stanford University in their paper "[node2vec: Scalable Feature Learning for Networks](https://arxiv.org/abs/1607.00653)"

The optimization of the mapped vectors themselves is done by a well-known machine learning method such as gradient descent. In the end, the result obtained can be used for node classification or link prediction, both truly popular.

![memgraph-node2Vec](https://public-assets.memgraph.com/19-graph-algorithms-that-you-can-use-right-now/memgraph-graph-algorithms-image19.png)

Illustration of how graph embeddings can be mapped to 2D space. Boundaries between classes are more visible than in a graph.

[Implementation Link](https://memgraph.com/docs/mage/algorithms/machine-learning-graph-analytics/node2vec-algorithm?utm_source=devto&utm_medium=referral&utm_campaign=blog_repost#implementation)

### 19. Graph Clustering

In [graph theory](https://en.wikipedia.org/wiki/Graph_theory), graph clustering is used to find subsets of similar nodes and group them together. It is part of graph analysis which has been attracting increasing attention in recent years due to the ubiquity of networks in the real world.

Graph clustering also known as network partitioning can be of two types:
* structure-based
* attribute-based clustering

The structure-based can be further divided into two categories, namely community-based, and structurally equivalent clustering.

Community-based methods aim to find dense subgraphs with a high number of intra-cluster edges and a low number of inter-cluster edges. Examples are the following algorithms:
* [A min-max cut algorithm for graph partitioning and data clustering](https://ieeexplore.ieee.org/document/989507)
* [Finding and evaluating community structure in networks](https://arxiv.org/abs/cond-mat/0308217)

Structural equivalence clustering, on the contrary, is designed to identify nodes with similar roles (like bridges and hubs). An example is [SCAN: A Structural Clustering Algorithm for Networks](http://web.cs.ucla.edu/~yzsun/classes/2014Spring_CS7280/Papers/Clustering/SCAN.pdf)

One example that can vary between community-based and structurally equivalent clustering is [Node2Vec](https://arxiv.org/abs/1607.00653).

Attribute-based methods utilize node labels, in addition to observed links, to cluster nodes like the following algorithm: [Graph clustering based on structural/attribute similarities](https://dl.acm.org/doi/10.14778/1687627.1687709)

![memgraph-graph-clustering](https://public-assets.memgraph.com/19-graph-algorithms-that-you-can-use-right-now/memgraph-graph-algorithms-image6.png)

![memgraph-graph-clustering-2](https://public-assets.memgraph.com/19-graph-algorithms-that-you-can-use-right-now/memgraph-graph-algorithms-image7.png)

Structure-based community clustering

[Implementation Link](https://memgraph.com/docs/mage/algorithms/machine-learning-graph-analytics/graph-clustering-algorithm?utm_source=devto&utm_medium=referral&utm_campaign=blog_repost#implementation)

## Conclusion
    
These are the top 19 graph algorithms to check out - there’s everything in here from Pagerank to Centrality. Give them a go and let us know if you have any challenges in using them with Memgraph by posting on [Discourse](https://discourse.memgraph.com) or [Discord](https://discord.gg/memgraph)


[![Read more about graph algorithms on memgraph.com](https://public-assets.memgraph.com/external/memgraph-read-more-gradient-1200.png)](https://memgraph.com/blog?topics=Graph+Algorithms&utm_source=devto&utm_medium=referral&utm_campaign=blog_repost&utm_content=banner#list)