Michael Walker
From Maps to Graphs Make Intersections Vertices Make Roads Edges Result is Weighted Directed Graph Weights: Speed Limit Length Tolls, Number of Lanes, Traffic Information
Data Structures Queue Stack Priority Queue
Queue First In First Out (FIFO) Think checkout line at a store Efficient Addition and removal are constant time
Stack First in Last Out (FILO) Alternatively Last in First out (LIFO) Think stack of plates Also efficient Addition and removal are constant time
Priority Queue Each element has priority Highest priority removed first
Where to Start? Start with finding ANY path Find a spanning tree Algorithm Idea: From start, create tree going outwards Depth First Search Breadth First Search Shortest Edge First (Prim’s Algorithm)
Depth First Search (DFS) Continue down one path until reaching a “dead end” Then backtrack and choose a different path Programmatically: Remove vertex from stack, set as “current vertex” Add current vertex to spanning tree if it not present (if present skip next step) Add adjacent vertices to stack if not in tree
Breadth First Search (DFS) Explore all paths in order of # of edges Programmatically: Remove vertex from queue, set as “current vertex” Add current vertex to spanning tree if it not present (if present skip next step) Add adjacent vertices to queue if not in tree
Prim’s Algorithm Shortest Edge First Creates Minimal Spanning Tree Spanning tree with the lowest possible sum of the edge weights Uses Priority Queue Instead of highest removed, lowest is removed
Kruskal’s Algorithm Also finds minimum spanning tree Builds a forest that forms a tree Algorithm: Select smallest unprocessed edge If two vertices are not part of the same tree, then add edge to forest Repeat until all vertices are in forest
Dijkstra’s Algorithm Resembles Prim’s Algorithm Total cost is used instead of edge cost Tentative costs are maintained and updated Algorithm Loop: Vertex with next lowest tentative distance is “current” vertex. For vertices adjacent to current vertex ○ Compare tentative distance to current vertex distance + edge ○ If new distance is lower, replace tentative distance Add current vertex to spanning tree.
Board Example
A* Algorithm Improvement to Dijkstra’s Algorithm Roadmaps are not abstract mathematical constructions Possible to add heuristic from real world Heuristic Conditions: Must only underestimate, never overestimate Overestimation runs faster, but produces non optimal paths
A* Algorithm Algorithm Loop: Vertex with next lowest tentative distance + heuristic distance is “current” vertex. For vertices adjacent to current vertex ○ Compare tentative distance to current vertex distance + edge ○ If new distance is lower, replace tentative distance Add current vertex to spanning tree.
A* Web Examples ar/AStar.html ar/AStar.html /AStarRouter.html /AStarRouter.html baur.de/cs.web.mashup.pathfinding.html baur.de/cs.web.mashup.pathfinding.html
Further Exploration Bi-Directional Search Simultaneously run A* from both start and end Reduce Dataset: Multi-Leveled Maps One graph for large cities One graph for county/city level One graph for town/borough level Google seamlessly does this with shortcuts Multi-point and simultaneous path finding Incomplete data path finding (D*)
References Johnsonbaugh, Richard, and Marcus Schaefer. Algorithms. Upper Saddle River, NJ: Pearson Education, Print. Khuller, Samir, Balaji Raghavachari, and Neal Young. "Balancing Minimum Spanning and Shortest Path Trees." Web. 29 Apr Kruskal, Joseph B. "On The Shortest Spanning Subtree Of A Graph And The Traveling Salesman Problem." AMS Journal (1955). Web. 29 Apr Patel, Amit J. "Amit’s Game Programming Information." Amit’s Patel's Personal Website. Stanford, Web. 29 Apr Prim, R. C. "Shortest Connection Networks And Some Generalizations." (1957): Web. 29 Apr Sanders, Peter. "Fast Route Planning." Google Tech Talk. 23 Mar Lecture.