Implement node-swapping heuristic