title: How to find the optimal grid placement for least distance between nodes of a network?
body: <p>If I wanted to display the nodes of a network on a 2D grid, but also I wanted to ensure the least amount of manhattan distance between any two directly connected nodes (where there is a maximum of one node per cell), what is the algorithm to do this?</p>
  
  <p>To clarify, let me provide an elementary example:</p>
  
  <p>A network has the following topology:
  A -> B -> C</p>
  
  <p>One solution of the grid placement would simply be to list the 3 items next to each other:</p>
  
  <p><code>| A | B | C |</code></p>
  
  <p>The distance between any two connecting nodes is 1 cell.</p>
  
  <p>Suppose another network has the following topology:
  A -> B -> C -> D -> A</p>
  
  <p>One solution of the place for this network would be:
  <code>
  | A | B |
  | D | C |
  </code>
  The distance between A and B, B and C, C and D, and D and A are each 1 cell. B and D, and A and C are not directly connected, therefore their distances do not factor into the problem.</p>
  
  <p>The most optimal arrangement would be the one that provides the lowest sum distance between all directly connected nodes.</p>
  
  <p>Now, how would one do this for an arbitrary network? Any help would certainly be appreciated. :)</p>