Six degrees of Kevin Bacon <p>There are a couple other posts about degrees of Kevin Bacon, and the answers on those posts are similar to what I came up with myself before looking it up. But it's evident that I'm still doing something wrong from the results I get and the way the performance of my query falls off as I increase the degree of separation from Kevin Bacon.</p> <p>Here's my query to find all actors with one degree of Kevin Bacon:</p> <pre><code>match p=(:Person {name:"Kevin Bacon"})-[:ACTED_IN*..2]-(:Person) return p </code></pre> <p>If I understand correctly, that's equivalent to this:</p> <pre><code>match p=(:Person {name:"Kevin Bacon"})-[:ACTED_IN]-&gt;()&lt;-[:ACTED_IN]-(:Person) return p </code></pre> <p>And indeed, both of these queries return the same number of rows. But if I modify the first version of the query and increase the path length to 6 (i.e., three degrees of Kevin Bacon) it returns 978 rows. There are only 133 Person nodes in the database, so I would expect it to return at most 133 rows.</p> <p>My guess is that it's returning multiple paths to some of the Person nodes. How do I tell it to return only the shortest path to each? Basically, I want to perform a single depth-first or breadth-first search. I think it might involve <code>WITH</code>, but I don't really understand how to use that yet.</p>