Week 12 Sample Solution
A. Search Algorithms
Scenario: Siri is currently in Arad, and she wants to drive to Bucharest.

What is the solution for BFS?
Arad->Sibiu->Fagaras->Bucharest
What is the solution for A*? The heuristic function is the straight-line distance to Bucharest.
Arad->Sibiu->Rimnicu Vilcea->Pitesti->Bucharest
B. Neo4j
Task 2
Write a LOAD CSV statement that imports the roads into your database. Remember, the Countries have already been created, so after LOAD CSV you'll need to run a MATCH statement to find the countries listed in each row of roads.csv, and only CREATE a road between those two countries. Don't forget the distance property, which should also be a float.
Task 4
Task 4.1
Change the query to be a depth-first search (DFS) and run it. Are the results the same, or different - and why?
The results between BFS and DFS will differ in the order they visit nodes.
Task 4.2
Try running the A* source-target shortest path algorithm to find the shortest path between Spain and India.
Task 4.3
Create relationships of the type MINST between the Canada and every country reachable from Canada. Write a Cypher query to display the minimum spanning tree. Hint: the relationship type is MINST, not ROAD!
Last updated