Hamiltonian paths where the vertices are integer partitions

What you want is known as a Gray code for integer partitions.

It exists.

See C. D. Savage, Gray code sequences of partitions, Journal of Algorithms 10 (1989) 577-595. Disclaimer: I haven't actually read this paper. Other sources such as this 1997 survey by Savage and these class notes don't say what the construction is but say that it's complicated.


There are two great general sources for Gray codes on combinatorial objects you might enjoy:

1) Frank Ruskey's "Combinatorial Generation" book: http://tinyurl.com/yly4pq7

2) Don Knuth's "Art of Computer Programming", Vol. 4, Fascicle 2-4 (published separately - all excellent), see http://www-cs-faculty.stanford.edu/~uno/taocp.html

Preliminary versions of some of these can be downloaded from the internet archive: http://tinyurl.com/yfo57t4


There seems to be a general pattern indicated by your $n=6$ example. Here is a path for $n=7$:

1.  7
2.  6 + 1
3.  5 + 2
4.  5 + 1 + 1
5.  4 + 1 + 1 + 1
6.  4 + 2 + 1
7.  4 + 3
8.  3 + 3 + 1
9.  3 + 2 + 2
10. 2 + 2 + 2 + 1
11. 3 + 2 + 1 + 1
12. 3 + 1 + 1 + 1 + 1
13. 2 + 2 + 1 + 1 + 1
14. 2 + 1 + 1 + 1 + 1 + 1
15. 1 + 1 + 1 + 1 + 1 + 1 + 1

I have written this so that it is obvious that all 15 partitions of 7 are accounted for. Note the 10th partition.

Here is one for $n = 8$:

1.  8
2.  7 + 1
3.  6 + 2
4.  6 + 1 + 1
5.  5 + 1 + 1 + 1
6.  5 + 2 + 1
7.  5 + 3
8.  4 + 4
9.  4 + 3 + 1
10. 4 + 2 + 2
11. 4 + 2 + 1 + 1
12. 4 + 1 + 1 + 1 + 1
13. 3 + 1 + 1 + 1 + 1 + 1
14. 3 + 2 + 1 + 1 + 1
15. 3 + 3 + 1 + 1
16. 3 + 2 + 2 + 1
17. 3 + 3 + 2
18. 2 + 2 + 2 + 2
19. 2 + 2 + 2 + 1 + 1
20. 2 + 2 + 1 + 1 + 1 + 1
21. 2 + 1 + 1 + 1 + 1 + 1 + 1
22. 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1

$n=9$:

1.  9  
2.  8 + 1   
3.  7 + 2   
4.  7 + 1 + 1    
5.  6 + 1 + 1 + 1    
6.  6 + 2 + 1    
7.  6 + 3   
8.  5 + 4   
9.  5 + 3 + 1    
10. 5 + 2 + 2    
11. 5 + 2 + 1 + 1    
12. 5 + 1 + 1 + 1 + 1    
13. 4 + 1 + 1 + 1 + 1 + 1    
14. 4 + 2 + 1 + 1 + 1    
15. 4 + 2 + 2 + 1    
16. 4 + 3 + 1 + 1    
17. 4 + 4 + 1    
18. 4 + 3 + 2    
19. 3 + 3 + 3    
20. 3 + 3 + 2 + 1    
21. 3 + 2 + 2 + 2    
22. 2 + 2 + 2 + 2 + 1    
23. 3 + 2 + 2 + 1 + 1    
24. 3 + 3 + 1 + 1 + 1    
25. 3 + 2 + 1 + 1 + 1 + 1    
26. 2 + 2 + 2 + 1 + 1 + 1    
27. 3 + 1 + 1 + 1 + 1 + 1 + 1    
28. 2 + 2 + 1 + 1 + 1 + 1 + 1    
29. 2 + 1 + 1 + 1 + 1 + 1 + 1 + 1   
30. 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1