Skip to content

Nearest neighbour

Nearest neighbour is a greedy algorithm initially to find the shortest path among a graph. It is typically used to solve problems like Traveling Salesman.

It basically works like Prim's algorithm, but the next nearest vertice needs to be connected to the last one.

Complexity

Time complexity

  • Worst case: O(n2)
  • Best case: Ω(n2)