Papers
Topics
Authors
Recent
Search
2000 character limit reached

Nearest-Neighbor Interchange (NNI) Search

Updated 5 July 2026
  • Nearest-Neighbor Interchange (NNI) search is a method for exploring phylogenetic tree space by swapping adjacent subtrees to transform one tree into another.
  • It employs parallel subroutines—including tree linearization, edge sequence merge-sorting, and leaf permutation—to approximate weighted tree distances in O(log n) time.
  • Analyses of NNI-walks reveal that focusing solely on NNI moves to cover SPR neighborhoods can incur a quadratic overhead, highlighting key combinatorial challenges.

Searching arXiv for papers on nearest-neighbor interchange search and related phylogenetic tree search. I’m checking whether the arXiv search interface is available in this environment. Nearest-Neighbor Interchange (NNI) search denotes the exploration of phylogenetic tree space by sequences of local rearrangements in which two adjacent subtrees are swapped across an operating edge. In the literature represented by "Efficient Parallel Computation of Nearest Neighbor Interchange Distances" (Gast et al., 2012) and "Walks on SPR Neighborhoods" (Caceres et al., 2011), NNI search appears in two closely related forms: as the computation of an NNI sequence that transforms one weighted phylogeny into another, and as an NNI walk that traverses a prescribed neighborhood of trees. The topic therefore spans distance measures, approximation algorithms, parallel tree transformation, and the combinatorics of local-search trajectories.

1. Formal setting and elementary operations

Let TT be an unrooted binary phylogenetic tree on leaf set S={1,…,n}S=\{1,\dots,n\}. An internal edge ee of TT has four incident subtrees TA,TB,TC,TDT_A,T_B,T_C,T_D whose leaf-sets partition SS as A∣B∣C∣DA\mid B\mid C\mid D. A single nearest-neighbor-interchange (NNI) move at ee replaces the split A∪B∣C∪DA\cup B\mid C\cup D by one of the two alternative splits, say B∪C∣A∪DB\cup C\mid A\cup D, yielding a new tree S={1,…,n}S=\{1,\dots,n\}0 (Caceres et al., 2011).

The weighted formulation specializes this local move to 3-regular phylogenetic trees. Let S={1,…,n}S=\{1,\dots,n\}1 be three consecutive edges forming a path of length 3 in S={1,…,n}S=\{1,\dots,n\}2. The NNI-operation on the triplet S={1,…,n}S=\{1,\dots,n\}3 swaps the two subtrees hanging off S={1,…,n}S=\{1,\dots,n\}4 and S={1,…,n}S=\{1,\dots,n\}5 while keeping the rest of the tree fixed; the central edge S={1,…,n}S=\{1,\dots,n\}6 is called the operating edge. In a weighted phylogeny each edge S={1,…,n}S=\{1,\dots,n\}7 has a nonnegative weight S={1,…,n}S=\{1,\dots,n\}8, and the cost of S={1,…,n}S=\{1,\dots,n\}9 is ee0 (Gast et al., 2012).

These definitions induce two standard search objects. The NNI distance ee1 is the minimum number of NNI moves transforming ee2 into ee3. In the weighted setting, the weighted NNI-distance between two weighted phylogenies ee4 on the same leaf-set and the same multiset of edge-weights is

ee5

One often writes

ee6

An NNI-walk is a sequence of trees

ee7

where each consecutive pair ee8 differ by exactly one NNI move; its length is ee9, the total number of NNI steps (Caceres et al., 2011). This distinction between optimizing transformation cost and organizing a walk through a neighborhood is central to the theory of NNI search.

2. Shared edges, bad edges, and decomposability

A principal structural notion for weighted NNI search is the good edge-pair. Let TT0 be two weighted phylogenies. An internal edge TT1 and TT2 form a good edge-pair if and only if:

  • TT3,
  • the partition of the leaf-labels induced by removing TT4 equals that induced by removing TT5,
  • the partition of the remaining internal-edge-weights induced by removing TT6 equals that induced by removing TT7 (Gast et al., 2012).

Any edge with no matching partner in the other tree is called a bad edge. Good edge-pairs can be used to split the big instance into independent smaller subinstances. This is the first step of the parallel approximation strategy: detect good edge-pairs in TT8, split TT9 along good edges into sub-problems, and then assume without loss of generality that no good edges remain (Gast et al., 2012).

The reduction is algorithmically significant because it isolates the part of the search space in which all internal edge weights must effectively be rearranged. In this reduced case, if TA,TB,TC,TDT_A,T_B,T_C,T_D0 have no good edge-pairs and the sum of internal-edge-weights is TA,TB,TC,TDT_A,T_B,T_C,T_D1, then

TA,TB,TC,TDT_A,T_B,T_C,T_D2

The stated proof idea is that each internal edge weight must be moved at least once (Gast et al., 2012). This lower bound is the basis for the approximation-ratio analysis of parallel NNI search.

3. Parallel approximation framework for weighted NNI-distance

The parallel algorithm of (Gast et al., 2012) works in the standard Concurrent-Read, Concurrent-Write PRAM model, assuming TA,TB,TC,TDT_A,T_B,T_C,T_D3-time access to any shared memory cell and arbitrary but consistent resolution of simultaneous writes. The complexity goal is an overall running time TA,TB,TC,TDT_A,T_B,T_C,T_D4 using either TA,TB,TC,TDT_A,T_B,T_C,T_D5 or TA,TB,TC,TDT_A,T_B,T_C,T_D6 processors, with work near-linear.

At a high level, the algorithm follows the 4-phase structure of the DasGupta-He-Jiang-Li-Tromp-Zhang (2000) sequential TA,TB,TC,TDT_A,T_B,T_C,T_D7-approximation, with each subphase replaced by a parallel subroutine (Gast et al., 2012).

Step Operation Stated role
0 Detect good edge-pairs Split into sub-problems; assume no good edges remain
1 Auxiliary trees and linearization Build balanced auxiliary trees and transform trees into linear trees
2 Sort the internal-edge sequence Reorder internal edges by parallel block-pair merge-sort
3 Sort the leaf-permutation Reconcile balanced trees that differ by a permutation TA,TB,TC,TDT_A,T_B,T_C,T_D8 of their leaves
4 Concatenate all sequences Obtain an TA,TB,TC,TDT_A,T_B,T_C,T_D9-approximation

The auxiliary-tree step constructs for each SS0 a balanced auxiliary tree SS1 of the same leaf-labels and weights, but fully height-balanced and nondecreasing from root to leaves. Both SS2 and SS3 are then transformed into linear trees SS4 in SS5 time using SS6 processors. A linear tree is one in which every internal node is adjacent to at least one leaf (Gast et al., 2012).

The subsequent steps sort two different kinds of disorder. First, the internal-edge sequence of a linear tree is sorted to match a target sorted sequence. Second, once the auxiliary trees have identical internal-edge order, the residual difference is a permutation SS7 of leaf labels, which is implemented by transporting leaves along paths in a balanced tree. The total weight-sum is SS8, and by the lower bound SS9, the algorithm achieves an A∣B∣C∣DA\mid B\mid C\mid D0 approximation (Gast et al., 2012).

The main theorem is stated as follows: if A∣B∣C∣DA\mid B\mid C\mid D1 are two weighted phylogenies on A∣B∣C∣DA\mid B\mid C\mid D2 leaves with the same leaf-set and edge-weight multiset, then one can compute in A∣B∣C∣DA\mid B\mid C\mid D3 time on A∣B∣C∣DA\mid B\mid C\mid D4 (or A∣B∣C∣DA\mid B\mid C\mid D5) CRCW-PRAM processors an NNI-sequence of total weight

A∣B∣C∣DA\mid B\mid C\mid D6

where A∣B∣C∣DA\mid B\mid C\mid D7 (Gast et al., 2012).

4. Core parallel subroutines

The linearization subroutine transforms a 3-regular tree into a linear tree. It first precomputes, for each end-node A∣B∣C∣DA\mid B\mid C\mid D8, the path A∣B∣C∣DA\mid B\mid C\mid D9 upward to its first junction-node via parallel pointer-jumping in ee0. It then repeats, until no junction-nodes remain, a constant-time parallel phase in which end-paths activate junction-nodes, activated junctions generate the NNI moves that insert end-paths, and pointers are updated by contraction and re-splicing. Each of the ee1 iterations takes ee2 time with ee3 processors (Gast et al., 2012).

The edge-reordering subroutine, denoted Procedure ParallelEdgeMergeSortee4, performs an ee5-round parallel merge-sort of block-pairs. In round ee6, the internal-edge sequence is partitioned into blocks of length ee7, block-pairs are paired from the two ends inwards, and the ee8 edges within each block-pair are sorted or merged by computing, for each edge, its rank in the opposite block via ee9-time comparisons done in parallel. This produces a merged block of length A∪B∣C∪DA\cup B\mid C\cup D0 plus A∪B∣C∪DA\cup B\mid C\cup D1 NNI-moves per edge. The final block spans all edges in sorted order (Gast et al., 2012).

The leaf-permutation subroutine, Procedure ParallelLeafSortA∪B∣C∪DA\cup B\mid C\cup D2, assumes balanced binary trees A∪B∣C∪DA\cup B\mid C\cup D3 of depth A∪B∣C∪DA\cup B\mid C\cup D4 with the same multiset of leaf-labels permuted by A∪B∣C∪DA\cup B\mid C\cup D5. It decomposes A∪B∣C∪DA\cup B\mid C\cup D6 into disjoint cycles in A∪B∣C∪DA\cup B\mid C\cup D7 time on A∪B∣C∪DA\cup B\mid C\cup D8 processors. In parallel for each cycle, and for each element in the cycle, it transports the corresponding leaf from its current position to its target position along the unique path via A∪B∣C∪DA\cup B\mid C\cup D9 moves. Since the depth is B∪C∣A∪DB\cup C\mid A\cup D0, each cycle takes B∪C∣A∪DB\cup C\mid A\cup D1 time, and the total time is B∪C∣A∪DB\cup C\mid A\cup D2 on B∪C∣A∪DB\cup C\mid A\cup D3 processors (Gast et al., 2012).

The good-edge-pair detection subroutine reduces the problem to the partition-labeling problem. Each internal edge B∪C∣A∪DB\cup C\mid A\cup D4 is converted into a leaf of unique new label B∪C∣A∪DB\cup C\mid A\cup D5 encoding B∪C∣A∪DB\cup C\mid A\cup D6, both trees are rooted arbitrarily, and partition-labeling is solved in B∪C∣A∪DB\cup C\mid A\cup D7 time on B∪C∣A∪DB\cup C\mid A\cup D8 processors using the method of Hon-Kao-Lam-Sung-Yiu (2004). A final scan of partition-labels in both trees identifies any label B∪C∣A∪DB\cup C\mid A\cup D9 occurring on exactly one internal node in S={1,…,n}S=\{1,\dots,n\}00 and one in S={1,…,n}S=\{1,\dots,n\}01 as a good edge-pair (Gast et al., 2012).

The approximation-ratio proof is additive across these subroutines. Linearization moves each internal edge at most once, so its total is at most S={1,…,n}S=\{1,\dots,n\}02. In each of the S={1,…,n}S=\{1,\dots,n\}03 merge-sort rounds, every internal edge participates in exactly one block-merge and contributes its weight once, so the total is at most S={1,…,n}S=\{1,\dots,n\}04. In leaf-sorting, each leaf transport visits S={1,…,n}S=\{1,\dots,n\}05 edges, so the total weight is also at most S={1,…,n}S=\{1,\dots,n\}06. Hence the overall cost is at most S={1,…,n}S=\{1,\dots,n\}07 for some constant S={1,…,n}S=\{1,\dots,n\}08, and therefore at most S={1,…,n}S=\{1,\dots,n\}09 (Gast et al., 2012).

5. NNI walks on SPR neighborhoods

A second line of work studies NNI search not as a shortest transformation between two fixed trees, but as a walk that visits every tree in a prescribed neighborhood. In this setting, an SPR move on S={1,…,n}S=\{1,\dots,n\}10 consists of pruning some subtree S={1,…,n}S=\{1,\dots,n\}11 by cutting an edge S={1,…,n}S=\{1,\dots,n\}12, and then regrafting S={1,…,n}S=\{1,\dots,n\}13 onto a possibly different edge of the remaining tree, followed by suppressing any resulting degree-2 node to restore binarity. The SPR-neighborhood is

S={1,…,n}S=\{1,\dots,n\}14

Allen and Steel show that for any unrooted binary tree on S={1,…,n}S=\{1,\dots,n\}15 leaves,

S={1,…,n}S=\{1,\dots,n\}16

(Caceres et al., 2011).

The main theorem of (Caceres et al., 2011) states that for every unrooted binary tree S={1,…,n}S=\{1,\dots,n\}17 on S={1,…,n}S=\{1,\dots,n\}18 leaves, any NNI-walk that visits all trees in S={1,…,n}S=\{1,\dots,n\}19 has length

S={1,…,n}S=\{1,\dots,n\}20

where S={1,…,n}S=\{1,\dots,n\}21. Equivalently,

S={1,…,n}S=\{1,\dots,n\}22

for some absolute constants S={1,…,n}S=\{1,\dots,n\}23 (Caceres et al., 2011).

The proof decomposes the SPR-neighborhood into orbits. For each edge S={1,…,n}S=\{1,\dots,n\}24 of S={1,…,n}S=\{1,\dots,n\}25, the orbit S={1,…,n}S=\{1,\dots,n\}26 is the set of all trees obtained by pruning exactly S={1,…,n}S=\{1,\dots,n\}27. One checks that S={1,…,n}S=\{1,\dots,n\}28, and there are S={1,…,n}S=\{1,\dots,n\}29 edges in S={1,…,n}S=\{1,\dots,n\}30. Orbits overlap only on the original tree S={1,…,n}S=\{1,\dots,n\}31 and on those SPR-neighbors obtainable by an NNI move of S={1,…,n}S=\{1,\dots,n\}32, exactly S={1,…,n}S=\{1,\dots,n\}33 such overlaps. Within each orbit S={1,…,n}S=\{1,\dots,n\}34, there is an NNI-circuit visiting every member of S={1,…,n}S=\{1,\dots,n\}35 with at most S={1,…,n}S=\{1,\dots,n\}36 steps, which yields the upper bound when circuits are spliced back-to-back via the base tree S={1,…,n}S=\{1,\dots,n\}37. The lower bound follows because, in each orbit, all but S={1,…,n}S=\{1,\dots,n\}38 trees form a subtree of the NNI-graph that has no edges leading out of S={1,…,n}S=\{1,\dots,n\}39, forcing S={1,…,n}S=\{1,\dots,n\}40 back-and-forth steps beyond a Hamiltonian pass, and therefore S={1,…,n}S=\{1,\dots,n\}41 extra steps overall (Caceres et al., 2011).

This result settles Bryant’s Second Combinatorial Conjecture. In the language of search, it shows that if the objective is to examine every SPR-neighbor by moving only through NNI-adjacent trees, then no Hamiltonian path exists and the shortest walk necessarily incurs quadratically many revisits beyond the number of distinct neighbors (Caceres et al., 2011).

6. Algorithmic significance, heuristics, and open problems

The two lines of work describe complementary aspects of NNI search. The weighted-distance results formalize how to construct an NNI-sequence between two trees under explicit complexity and approximation guarantees. The neighborhood-walk results formalize the unavoidable overhead of restricting traversal to NNI moves while trying to cover a larger SPR neighborhood. Taken together, they indicate that local-search behavior depends not only on the cost of individual NNI operations but also on the global geometry of the target set.

Several practical implications are stated explicitly in (Gast et al., 2012). Good-edge-pair splitting suggests a divide-and-conquer NNI-search: identify cheap shared edges first, solve subproblems in parallel. The linearization and block-merge steps give a structured way to propose NNI moves in S={1,…,n}S=\{1,\dots,n\}42 phases, which can seed multithreaded hill-climbing or simulated-annealing on large trees. A stated trade-off is parallelism versus local quality: the S={1,…,n}S=\{1,\dots,n\}43-approximate solution may be far from optimal on some instances, and mixing with local descent on bad edges may improve accuracy (Gast et al., 2012).

The neighborhood results supply a complementary worst-case warning. If a search strategy must examine every SPR-neighbor by hopping via NNI moves, it will make S={1,…,n}S=\{1,\dots,n\}44 more local moves than there are distinct neighbors. The same work notes that organizing SPR neighbors into orbits and precomputing DFS-like circuits per orbit provides a systematic way to visit all one-SPR neighbors with only S={1,…,n}S=\{1,\dots,n\}45 overhead, rather than naively random-walking through NNI space (Caceres et al., 2011).

Several open questions are stated in the weighted-distance work. The APX-hardness status of weighted NNI-distance remains open. It is also asked whether one can reduce the S={1,…,n}S=\{1,\dots,n\}46 factor in the approximation ratio or improve parallel time and work, and whether the same ideas can be adapted to SPR or TBR distances (Gast et al., 2012). These questions situate NNI search at the intersection of combinatorial phylogenetics, approximation algorithms, and parallel computation.

Definition Search Book Streamline Icon: https://streamlinehq.com
References (2)

Topic to Video (Beta)

Whiteboard

Follow Topic

Get notified by email when new papers are published related to Nearest-Neighbor Interchange (NNI) Search.