0% found this document useful (0 votes)
37 views

Neo 4 J

This document contains 9 questions about analyzing relationships between people in a Neo4j graph database. It asks questions about finding the shortest path between two actors, the length of that path, all shortest paths between people with certain first names, people connected to Kevin Bacon by a path of length 6, the number of people 6 degrees from Kevin Bacon, the average number of people 6 degrees from any person, the maximum distance between Kevin Bacon and another person, the maximum shortest path distance between any two people, and the distribution of all pairwise distances.

Uploaded by

Dare Devil
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

Neo 4 J

This document contains 9 questions about analyzing relationships between people in a Neo4j graph database. It asks questions about finding the shortest path between two actors, the length of that path, all shortest paths between people with certain first names, people connected to Kevin Bacon by a path of length 6, the number of people 6 degrees from Kevin Bacon, the average number of people 6 degrees from any person, the maximum distance between Kevin Bacon and another person, the maximum shortest path distance between any two people, and the distribution of all pairwise distances.

Uploaded by

Dare Devil
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

ASSIGNMENT_5

Neo4j

1. What is a shortest path (using any kind of relation) between Keanu


Reeves and Tom
Cruise?

Match ( p1: Person { name: “Tom Cruise” }), ( p2: Person { name: “Keanu
Revees” } ), path = shortestPath ( (p1) – [*..15] - (p2) )
Return p, length(p)

2. How long is the shortest path between Keanu Reeves and Tom
Cruise?

Match ( p1: Person { name: “Tom Cruise” } ), ( p2: Person { name: “Keanu
Revees” ) ), path = shortestPath ( (p1) – [*..15] - (p2) )
Return p, count(p)

3. What are the shortest paths between people with first name Keanu
and people with first name Tom?

Match ( p1: Person ), ( p2: Person ), path = shortestPath ( (p1) – [*..15] -


(p2) ) Where p1.name starts with “Tom” and p2.name starts with “Keanu”
Return p

4. Which persons have a distance of length 6 to Kevin Bacon (the


distance between two persons being the length of a shortest path
between them)?

Match ( p1: Person ), ( p2: Person ), path = shortestPath ( (p1) – [*..15] -


(p2) ) Where p1.name starts with “Kevin Bacon” and p1 <> p2 with p2,p and
length(p) = 5
Return p2
5. How many persons are there with distance 6 to Kevin Bacon?

Match ( p1: Person ), ( p2: Person ), path = shortestPath ( (p1) – [*..15] -


(p2) ) Where p1 <> p2 with p Where length(p) = 6
Return count(*)

6. What is the average number of persons with distance 6 to any


person?

Match ( p1: Person ), ( p2: Person ), path = shortestPath ( (p1) – [*..15] -


(p2) ) Where p1 <> p2 with p1,p Where length(p) = 6 With p1, count (*) as
c
Return avg(c)

7. What is the largest distance of any person to Kevin Bacon?

Match ( p1: Person ), ( p2: Person ), path = shortestPath ( (p1) – [*..15] -


(p2) ) Where p1.name starts with “Kevin Bacon” and p1 <> p2 with p
Return max( length(p) )

8. What is the largest shortest - path distance between any two


persons?

Match ( p1: Person ), ( p2: Person ), path = shortestPath ( (p1) – [*..15] -


(p2) ) Where p1 <>
Return max( length(p) )

9. What is the distribution of pairwise distances (i.e., for distance 1, 2,


3, ..., how many pairs of persons have that distance from each
other)

Match ( p1: Person ), ( p2: Person ), path = shortestPath ( (p1) – [*..15] -


(p2) ) Where p1 <> p2 with length(p) as length
Return length, count(*) as count
Order By length

You might also like