Neighbor Joining: A Bottom-Up Approach to Phylogenetic Tree Construction
In the field of bioinformatics, neighbor joining is a widely used bottom-up (agglomerative) clustering method designed to create phylogenetic trees. Developed by Naruya Saitou and Masatoshi Nei in 1987, this algorithm typically utilizes DNA or protein sequence data. To reconstruct the evolutionary relationships between different taxa—such as species or specific sequences—the algorithm relies on a distance matrix that quantifies the genetic distance between every pair of taxa in the set.
Key Facts
- Methodology: An agglomerative clustering approach that transforms a distance matrix into a resolved tree.
- Input: Requires a distance matrix specifying the distance between each pair of taxa.
- Efficiency: Significantly faster than maximum likelihood or maximum parsimony methods, making it ideal for large datasets.
- Key Advantage: Does not assume a constant rate of evolution (unlike the molecular clock hypothesis used in UPGMA).
- Limitation: May occasionally assign negative lengths to certain branches.
The Neighbor Joining Algorithm
The process begins with a completely unresolved tree, known as a star network, where all taxa are connected to a single central node. The algorithm then iteratively resolves this network through the following steps:
- Q-Matrix Calculation: A Q matrix is calculated based on the current distance matrix to identify the closest neighbors.
- Node Joining: The pair of distinct taxa (i and j) with the smallest value in the Q matrix are joined to a new internal node.
- Branch Length Estimation: The distances from the joined taxa to the new node are calculated.
- Distance Update: The distances from all other taxa to the new node are computed.
- Iteration: The joined pair is replaced by the new node in the distance matrix, and the process repeats until the tree is fully resolved.

The Q-Matrix and Distance Calculations
The Q matrix is the core selection tool of the algorithm. It is derived from the distance matrix to ensure that the joined pair is the most appropriate based on the overall tree structure. Once a pair is joined to a new node (u), the branch lengths from the taxa to that node are fixed and do not change in subsequent steps.
For any taxon not involved in the current joining step, its distance to the new node is calculated using the distances to the two taxa that were just joined. This ensures the tree maintains a consistent geometric representation of the genetic distances.
Computational Complexity and Performance
Implementing neighbor joining in a straightforward manner results in a time complexity of O(n3), where n is the number of taxa. This is because the algorithm requires multiple iterations, and at each step, a matrix must be built and searched. However, modern implementations often use heuristics to improve average performance.

Additive Distances and Accuracy
A distance matrix is considered additive if the sum of the branch lengths between any two taxa on the resulting tree exactly equals the distance provided in the input matrix. While perfectly additive matrices are rare in nature, neighbor joining is guaranteed to find the correct tree if the input is additive. It also remains accurate if the matrix is "nearly additive," meaning the errors in the distance matrix are less than half the length of the shortest branch in the tree.
Comparison with Other Methods
Neighbor joining is often viewed as a greedy heuristic for the balanced minimum evolution (BME) criterion, which seeks the tree topology that minimizes the total sum of branch lengths. While it doesn't always find the absolute BME optimum, it usually comes very close.
| Method | Approach | Key Advantage | Key Disadvantage |
|---|---|---|---|
| Neighbor Joining | Distance-based | Very fast; handles large datasets | Can produce negative branch lengths |
| UPGMA/WPGMA | Distance-based | Simple implementation | Assumes constant evolutionary rate |
| Maximum Likelihood | Character-based | High statistical accuracy | Computationally expensive |
| Maximum Parsimony | Character-based | Simplest evolutionary explanation | Can be computationally prohibitive |
Implementations and Variants
Several state-of-the-art programs implement canonical neighbor joining, including RapidNJ and NINJA, which typically operate with run times proportional to the square of the number of taxa. Other specialized variants include:
- BIONJ and Weighbor: These improve accuracy by giving more weight to shorter, more reliable distances.
- FastME: An implementation of the BME method that uses topological moves like Nearest Neighbor Interchanges (NNI) to refine the tree.
- FastTree: Uses sequence profiles and approximates maximum-likelihood for very large alignments.
- NeighborNet: A variant that produces phylogenetic networks instead of traditional trees.
Frequently Asked Questions
What is the primary input required for neighbor joining?
The primary input is a distance matrix that specifies the genetic distance between every pair of taxa (species or sequences) being analyzed.
How does neighbor joining differ from UPGMA?
Unlike UPGMA, neighbor joining does not assume that all lineages evolve at the same rate, meaning it does not rely on the molecular clock hypothesis.
What is a "star network" in the context of this algorithm?
A star network is the initial, completely unresolved tree topology where all taxa are connected to a single central node before the iterative joining process begins.
Can neighbor joining produce incorrect trees?
While it is statistically consistent and accurate for additive or nearly additive matrices, it can be superseded by character-based methods that offer higher accuracy under certain complex evolutionary conditions.
What is the time complexity of the standard NJ algorithm?
The straightforward implementation has a time complexity of O(n3), though optimized versions and heuristics can reduce this in practice.