CS106X – Programming Abstractions in C++ Cynthia Bailey Lee Dijkstra’s animation slides by Keith Schwarz CS2 in C++ Peer Instruction Materials by Cynthia.

Slides:



Advertisements
Similar presentations
Problem solving with graph search
Advertisements

Chapter 9: Graphs Shortest Paths
CS 206 Introduction to Computer Science II 04 / 01 / 2009 Instructor: Michael Eckmann.
CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
Informed Search Methods How can we improve searching strategy by using intelligence? Map example: Heuristic: Expand those nodes closest in “as the crow.
Chapter 8, Part I Graph Algorithms.
1 Graphs: Traversal Searching/Traversing a graph = visiting the vertices of a graph by following the edges in a systematic way Example: Given a highway.
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
CS171 Introduction to Computer Science II Graphs Strike Back.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 CHAPTER 4 - PART 2 GRAPHS 1.
State Space Search Algorithms CSE 472 Introduction to Artificial Intelligence Autumn 2003.
Tirgul 12 Algorithm for Single-Source-Shortest-Paths (s-s-s-p) Problem Application of s-s-s-p for Solving a System of Difference Constraints.
1 Greedy Algorithms. 2 2 A short list of categories Algorithm types we will consider include: Simple recursive algorithms Backtracking algorithms Divide.
Directed Graph Algorithms CSE 373 Data Structures Lecture 14.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Graphs.
Graphs. Graph definitions There are two kinds of graphs: directed graphs (sometimes called digraphs) and undirected graphs Birmingham Rugby London Cambridge.
Spring 2010CS 2251 Graphs Chapter 10. Spring 2010CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs.
Shortest Path Problems Directed weighted graph. Path length is sum of weights of edges on path. The vertex at which the path begins is the source vertex.
CSE 373: Data Structures and Algorithms Lecture 18: Graphs II 1.
CSE 780 Algorithms Advanced Algorithms Graph Algorithms Representations BFS.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
CISC220 Fall 2009 James Atlas Nov 13: Graphs, Line Intersections.
More Graph Algorithms Weiss ch Exercise: MST idea from yesterday Alternative minimum spanning tree algorithm idea Idea: Look at smallest edge not.
1 Shortest Path Calculations in Graphs Prof. S. M. Lee Department of Computer Science.
CS106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.
Dijkstra’s Algorithm and Heuristic Graph Search David Johnson.
1 GRAPHS - ADVANCED APPLICATIONS Minimim Spanning Trees Shortest Path Transitive Closure.
CS 146: Data Structures and Algorithms July 21 Class Meeting
CS106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
Charles Lin. Graph Representation Graph Representation DFS DFS BFS BFS Dijkstra Dijkstra A* Search A* Search Bellman-Ford Bellman-Ford Floyd-Warshall.
CS106X – Programming Abstractions in C++ Cynthia Bailey Lee BFS animation slides by Keith Schwarz CS2 in C++ Peer Instruction Materials by Cynthia Bailey.
COSC 2007 Data Structures II Chapter 14 Graphs III.
Representing and Using Graphs
P ROBLEM Write an algorithm that calculates the most efficient route between two points as quickly as possible.
Common final examinations When: Wednesday, 12/11, 3:30-5:30 PM Where: Ritter Hall - Walk Auditorium 131 CIS 1166 final When: Wednesday, 12/11, 5:45-7:45.
Dijkstra’s Algorithm Supervisor: Dr.Franek Ritu Kamboj
COMP261 Lecture 7 A* Search. A* search Can we do better than Dijkstra's algorithm? Yes! –want to explore more promising paths, not just shortest so far.
CS106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.
Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada ece.uwaterloo.ca.
Dijkstra’s Algorithm: single source shortest paths David Kauchak cs62 Spring 2010.
COMP261 Lecture 6 Dijkstra’s Algorithm. Connectedness Is this graph connected or not? A Z FF C M N B Y BB S P DDGG AA R F G J L EE CC Q O V D T H W E.
Review: Tree search Initialize the frontier using the starting state While the frontier is not empty – Choose a frontier node to expand according to search.
10 Copyright © William C. Cheng Data Structures - CSCI 102 Graph Terminology A graph consists of a set of Vertices and a set of Edges C A B D a c b d e.
Week 12 - Monday.  What did we talk about last time?  Topological sort and cycle detection in directed graphs  Connectivity  Strong connectivity.
Introduction to Graphs And Breadth First Search. Graphs: what are they? Representations of pairwise relationships Collections of objects under some specified.
Programming Abstractions Cynthia Lee CS106X. Upcoming Topics Graphs! 1.Basics  What are they? How do we represent them? 2.Theorems  What are some things.
REFERENCE: “ARTIFICIAL INTELLIGENCE FOR GAMES”, IAN MILLINGTON. A* (A-STAR)
Slides by: Eric Ringger, adapted from slides by Stuart Russell of UC Berkeley. CS 312: Algorithm Design & Analysis Lecture #36: Best-first State- space.
1 Directed Graphs Chapter 8. 2 Objectives You will be able to: Say what a directed graph is. Describe two ways to represent a directed graph: Adjacency.
Chapter 3.5 and 3.6 Heuristic Search Continued. Review:Learning Objectives Heuristic search strategies –Best-first search –A* algorithm Heuristic functions.
Chapter 05 Introduction to Graph And Search Algorithms.
CS106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.
Programming Abstractions Cynthia Lee CS106B. Upcoming Topics Graphs! 1.Basics  What are they? How do we represent them? 2.Theorems  What are some things.
Graphs. Introduction Graphs are a collection of vertices and edges Graphs are a collection of vertices and edges The solid circles are the vertices A,
CSE 373: Data Structures and Algorithms Lecture 21: Graphs V 1.
1 A* search Outline In this topic, we will look at the A* search algorithm: –It solves the single-source shortest path problem –Restricted to physical.
Heaps and Priority Queues
Programming Abstractions
Programming Abstractions
Programming Abstractions
Cse 373 May 8th – Dijkstras.
Programming Abstractions
Programming Abstractions
CSE332: Data Abstractions Lecture 17: Shortest Paths
Richard Anderson Spring 2016
Directed Graphs (Part II)
Presentation transcript:

CS106X – Programming Abstractions in C++ Cynthia Bailey Lee Dijkstra’s animation slides by Keith Schwarz CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License. Permissions beyond the scope of this license may be available at Bailey LeeCreative Commons Attribution-NonCommercial- ShareAlike 4.0 International Licensehttp://peerinstruction4cs.org

Graphs Note about representation of graphs in Trailblazer assignment (compared to our two canonical graph representation forms: adjacency matrix and adjacency list)

V1V2V3V4V5V6 V V V V V V Representing Graphs: Adjacency Matrix vs. Trailblazer v1v2v3v4v5v6 v7v8v9v10v11v12 v13v14v15v16…

Breadth-First Search Graph algorithms

Breadth-First Search AB EF CD GH IJ L K

J L G I H CAB E D K F AB EF CD GH IJ L K THINGS TO NOTICE: (1)We used a queue (2)What’s left is kind of a subset of the edges, in the form of ‘parent’ pointers (3)If you follow the parent pointers from the desired endpoint, you will get back to the start point, and it will be the shortest way to do that.

J L G I H CAB E D K F AB EF CD GH IJ L K Breadth-First Search THINGS TO NOTICE: (4) We now have the answer to the question “What is the shortest path to you from F?” for every single node in the graph!!

But wait!!  What you calculated will find the shortest path in terms of fewest number of road segments but doesn’t at all take into account how long each road segment is! 

But wait!!  This might be useful if you are a fugitive and want to go from one city to another passing through the fewest other cities on the way…  But what if we want to save gas/fewest miles?

Dijkstra’s Shortest Paths (Like Breadth-first Search, but takes into account weight/distance between nodes)

Edsger Dijkstra  “Goto considered harmful” (title given to his letter) This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license. CommonsAttribution-Share Alike 3.0 Unported  THE multiprogramming system (operating system)  Layers of abstraction!!  Complier for a language that can do recursion  Dining Philosopher’s Problem (resource contention and deadlock)  Dijkstra’s algorithm

The Shortest Path Problem ● Suppose that you have a graph representing different locations ● Each edge has an associated cost (or weight, length, etc) ● We'll assume costs are nonnegative* ● Goal: Find the least-cost (or lowest-weight, lowest-length, etc) path from some node u to a node v * else use the Bellman–Ford algorithm

BAC DE HG F I BAC DE HG F I

● Mark all nodes as gray. ● Mark the initial node s as yellow and at candidate distance 0. ● Enqueue s into the priority queue with priority 0. ● While not all nodes have been visited: ● Dequeue the lowest-cost node u from the priority queue. ● Color u green. The candidate distance d that is currently stored for node u is the length of the shortest path from s to u. ● If u is the destination node t, you have found the shortest path from s to t and are done. ● For each node v connected to u by an edge of length L: – If v is gray: ● Color v yellow. ● Mark v's distance as d + L. ● Set v's parent to be u. ● Enqueue v into the priority queue with priority d + L. – If v is yellow and the candidate distance to v is greater than d + L: ● Update v's candidate distance to be d + L. ● Update v's parent to be u. ● Update v's priority in the priority queue to d + L. Dijkstra's Algorithm

ABA 0? C DE HG F I BC DE HG F I

ABA 0? C DE HG F I BC DE HG F I A 0? 7 1

ABA 0? C DE HG F I BC DE HG F I A 0? 7 1

ABA 0? C DE HG F I BC DE HG F I

ABA0A0 C DE HG F I BC DE HG F I

B D AB 6? A0A0 C D 3? E HG F I C E HG F I

B D AB 6? A0A0 C D 3? E HG F I C E HG F I B 6? D 3? 7 1

B D AB 6? A0A0 C D 3? E HG F I C E HG F I B 6? D 3? 7 1

B D AB 6? A0A0 C D 3? E HG F I C E HG F I B 6? D 3? 7 1

B D AB 6? A0A0 C D 3? E HG F I C E HG F I B 6? 7 1

B D AB 6? A0A0 C D3D3 E HG F I C E HG F I B 6? 7 1

E G B D AB 6? A0A0 C D3D3 E 4? HG 12? F I C H F I B 6? 7 1

E G B D AB 6? A0A0 C D3D3 E 4? HG 12? F I C H F I B 6? 7 1

E G B D AB 6? A0A0 C D3D3 E 4? HG 12? F I C H F I B 6? E 4? G 12? 7 1

E G B D AB 6? A0A0 C D3D3 E 4? HG 12? F I C H F I B 6? E 4? G 12? 7 1

E G B D AB 6? A0A0 C D3D3 E 4? HG 12? F I C H F I B 6? E 4? G 12? 7 1

E G B D AB 6? A0A0 C D3D3 E 4? HG 12? F I C H F I B 6? G 12? 7 1

E G B D AB 6? A0A0 C D3D3 E4E4 HG 12? F I C H F I B 6? G 12? 7 1

H FE G B D AB 6? A0A0 C D3D3 E4E4 H 8? G 12? F 11? I C I B 6? G 12? 7 1

H FE G B D AB 6? A0A0 C D3D3 E4E4 H 8? G 12? F 11? I C I B 6? G 12? 7 1

H FE G B D AB 6? A0A0 C D3D3 E4E4 H 8? G 12? F 11? I C I B 6? G 12? H 8? F 11? 7 1

H FE G B D AB 6? A0A0 C D3D3 E4E4 H 8? G 12? F 11? I C I B 6? G 12? H 8? F 11? 7 1

H FE G B D AB 5? A0A0 C D3D3 E4E4 H 8? G 12? F 11? I C I B 6? G 12? H 8? F 11? 7 1

H FE G B D AB 5? A0A0 C D3D3 E4E4 H 8? G 12? F 11? I C I B 5? G 12? H 8? F 11? 7 1

H FE G B D AB 5? A0A0 C D3D3 E4E4 H 8? G 12? F 11? I C I B 5? G 12? H 8? F 11? 7 1

H FE G B D AB 5? A0A0 C D3D3 E4E4 H 8? G 12? F 11? I C I B 5? G 12? H 8? F 11? 7 1

H FE G B D AB 5? A0A0 C D3D3 E4E4 H 8? G 12? F 11? I C I B 5? G 12? H 8? F 11? 7 1

H FE G B D AB 5? A0A0 C D3D3 E4E4 H 8? G 12? F 11? I C I G 12? H 8? F 11? 7 1

H FE G B D AB5B5 A0A0 C D3D3 E4E4 H 8? G 12? F 11? I C I G 12? H 8? F 11? 7 1

C H FE G B D AB5B5 A0A0 C 8? D3D3 E4E4 H 8? G 12? F 11? II G 12? H 8? F 11? 7 1

C H FE G B D AB5B5 A0A0 C 8? D3D3 E4E4 H 8? G 12? F 11? II G 12? H 8? F 11? 7 1

C H FE G B D AB5B5 A0A0 C 8? D3D3 E4E4 H 8? G 12? F 11? II G 12? H 8? F 11? C 8? 7 1

C H FE G B D AB5B5 A0A0 C 8? D3D3 E4E4 H 8? G 12? F 11? II G 12? H 8? F 11? C 8? 7 1

C H FE G B D AB5B5 A0A0 C 8? D3D3 E4E4 H 8? G 12? F 11? II G 12? H 8? F 11? C 8? 7 1

C H FE G B D AB5B5 A0A0 C 8? D3D3 E4E4 H 8? G 12? F 11? II G 12? H 8? F 11? C 8? 7 1 You predict the next queue state: A.H,C,F,G,I B.C,F,G,I C.C,G,F,I D.Other/none/ more

C H FE G B D AB5B5 A0A0 C 8? D3D3 E4E4 H 8? G 12? F 11? II G 12? F 11? C 8? 7 1

C H FE G B D AB5B5 A0A0 C 8? D3D3 E4E4 H8H8 G 12? F 11? II G 12? F 11? C 8? 7 1

I C H FE G B D AB5B5 A0A0 C 8? D3D3 E4E4 H 8? G 12? F 11? I 13? G 12? F 11? C 8? H8H8 7 1

I C H FE G B D AB5B5 A0A0 C 8? D3D3 E4E4 H 8? G 12? F 11? I 13? G 12? F 11? C 8? H8H8 7 I 13? 1

I C H FE G B D AB5B5 A0A0 C 8? D3D3 E4E4 H 8? G 12? F 11? I 13? G 12? F 11? C 8? H8H8 7 I 13? 1

I C H FE G B D AB5B5 A0A0 C 8? D3D3 E4E4 H 8? G 10? F 11? I 13? G 12? F 11? C 8? H8H8 7 I 13? 1

I C H FE G B D AB5B5 A0A0 C 8? D3D3 E4E4 H 8? G 10? F 11? I 13? G 10? F 11? C 8? H8H8 7 I 13? 1

I C H FE G B D AB5B5 A0A0 C 8? D3D3 E4E4 H 8? G 10? F 11? I 13? G 10? F 11? C 8? H8H8 7 I 13? 1

I C H FE G B D AB5B5 A0A0 C 8? D3D3 E4E4 H 8? G 10? F 11? I 13? G 10? F 11? C 8? H8H8 7 I 13? I 13? 1

I C H FE G B D AB5B5 A0A0 C 8? D3D3 E4E4 H 8? G 10? F 11? I 13? G 10? F 11? C 8? H8H8 7 I 13? 1

I C H FE G B D AB5B5 A0A0 C 8? D3D3 E4E4 H 8? G 10? F 11? I 13? G 10? F 11? C 8? H8H8 7 I 13? 1

I C H FE G B D AB5B5 A0A0 C 8? D3D3 E4E4 H8H8 G 10? F 11? I 13? G 10? F 11? C 8? 7 I 13? 1

I C H FE G B D AB5B5 A0A0 C 8? D3D3 E4E4 H8H8 G 10? F 11? I 13? G 10? F 11? C 8? 7 I 13?

I C H FE G B D AB5B5 A0A0 C 8? D3D3 E4E4 H8H8 G 10? F 11? I 13? G 10? F 11? 7 I 13?

I C H FE G B D AB5B5 A0A0 C8C8 D3D3 E4E4 H8H8 G 10? F 11? I 13? G 10? F 11? 7 I 13?

I C H FE G B D AB5B5 A0A0 C8C8 D3D3 E4E4 H8H8 G 10? F 11? I 13? G 10? F 11? 7 I 13?

I C H FE G B D AB5B5 A0A0 C8C8 D3D3 E4E4 H8H8 G 10? F 9? I 13? G 10? F 9? 7 I 13?

I C H FE G B D AB5B5 A0A0 C8C8 D3D3 E4E4 H8H8 G 10? F 9? I 13? G 10? F 9? 7 I 13?

I C H FE G B D AB5B5 A0A0 C8C8 D3D3 E4E4 H8H8 G 10? F 9? I 13? G 10? F 9? 7 I 13?

I C H FE G B D AB5B5 A0A0 C8C8 D3D3 E4E4 H8H8 G 10? F 9? I 13? G 10? F 9? 7 I 13?

I C H FE G B D AB5B5 A0A0 C8C8 D3D3 E4E4 H8H8 G 10? F 9? I 13? G 10? F 9? 7 I 13?

I C H FE G B D AB5B5 A0A0 C8C8 D3D3 E4E4 H8H8 G 10? F 9? I 13? G 10? F 9? 7 I 13? 1

I C H FE G B D AB5B5 A0A0 C8C8 D3D3 E4E4 H8H8 G 10? F 9? I 13? G 10? F 9? 7 I 13? 1

I C H FE G B D AB5B5 A0A0 C8C8 D3D3 E4E4 H8H8 G 10? F 9? I 13? G 10? 7 I 13? 1

I C H FE G B D AB5B5 A0A0 C8C8 D3D3 E4E4 H8H8 G 10? F9F9 I 13? G 10? 7 I 13? 1

I C H FE G B D AB5B5 A0A0 C8C8 D3D3 E4E4 H8H8 G 10? F9F9 I 13? G 10? 7 I 13? 1

I C H FE G B D AB5B5 A0A0 C8C8 D3D3 E4E4 H8H8 G 10? F9F9 I 13? G 10? 7 I 13? 1

I C H FE G B D AB5B5 A0A0 C8C8 D3D3 E4E4 H8H8 G 10? F9F9 I 13? G 10? 7 I 13? 1

I C H FE G B D AB5B5 A0A0 C8C8 D3D3 E4E4 H8H8 G 10? F9F9 I 13? G 10? 7 I 13? 1

I C H FE G B D AB5B5 A0A0 C8C8 D3D3 E4E4 H8H8 G 10? F9F9 I 13? G 10? 7 I 13? 1

I C H FE G B D AB5B5 A0A0 C8C8 D3D3 E4E4 H8H8 G 10? F9F9 I 13? I 13? 1

I C H FE G B D AB5B5 A0A0 C8C8 D3D3 E4E4 H8H8 G 10 F9F9 I 13? I 13? 1

I C H FE G B D AB5B5 A0A0 C8C8 D3D3 E4E4 H8H8 G 10 F9F9 I 13? I 13? 1

I C H FE G B D AB5B5 A0A0 C8C8 D3D3 E4E4 H8H8 G 10 F9F9 I 13? I 13? 1

I C H FE G B D AB5B5 A0A0 C8C8 D3D3 E4E4 H8H8 G 10 F9F9 I 13?

I C H FE G B D AB5B5 A0A0 C8C8 D3D3 E4E4 H8H8 G 10 F9F9 I

I C H FE G B D AB5B5 A0A0 C8C8 D3D3 E4E4 H8H8 G 10 F9F9 I

Dijkstra's Algorithm ● Split nodes apart into three groups: ● Green nodes, where we already have the shortest path; ● Gray nodes, which we have never seen; and ● Yellow nodes that we still need to process. ● Dijkstra's algorithm works as follows: ● Mark all nodes gray except the start node, which is yellow and has cost 0. ● Until no yellow nodes remain: – Choose the yellow node with the lowest total cost. – Mark that node green. – Mark all its gray neighbors yellow and with the appropriate cost. – Update the costs of all adjacent yellow nodes by considering the path through the current node.

An Important Note ● The version of Dijkstra's algorithm I have just described is not the same as the version described in the course reader. ● This version is more complex than the book's version, but is much faster. ● THIS IS THE VERSION YOU MUST USE ON YOUR TRAILBLAZER ASSIGNMENT!

How Dijkstra's Works ● Dijkstra's algorithm works by incrementally computing the shortest path to intermediary nodes in the graph in case they prove to be useful. ● Most of these nodes are completely in the wrong direction. ● No “big-picture” conception of how to get to the destination – the algorithm explores outward in all directions. ● Could we give the algorithm a hint?

Heuristics ● In the context of graph searches, a heuristic function is a function that guesses the distance from some known node to the destination node. ● The guess doesn't have to be correct, but it should try to be as accurate as possible. ● Examples: For Google Maps, a heuristic for estimating distance might be the straight-line “as the crow flies” distance.

Admissible Heuristics ● A heuristic function is called an admissible heuristic if it never overestimates the distance from any node to the destination. ● In other words: ● predicted-distance ≤ actual-distance

Why Heuristics Matter ● We can modify Dijkstra's algorithm by introducing heuristic functions. ● Given any node u, there are two associated costs: ● ● The actual distance from the start node s. ● The heuristic distance from u to the end node t. ● Key idea: Run Dijkstra's algorithm, but use the following priority in the priority queue: ● priority(u) = distance(s, u) + heuristic(u, t) ● This modification of Dijkstra's algorithm is called the A* search algorithm. stu

A* Search ● As long as the heuristic is admissible (and satisfies one other technical condition), A* will always find the shortest path from the source to the destination node. ● Can be dramatically faster than Dijkstra's algorithm. ● Focuses work in areas likely to be productive. ● Avoids solutions that appear worse until there is evidence they may be appropriate.

Close Cousins ● Dijkstra's algorithm and A* search are very closely related: ● Dijkstra's uses a node's candidate distance as its priority. ● A* uses a node's candidate distance plus a heuristic value as its priority. ● Interesting fact: If you use the zero heuristic (which always predicts a node is at distance 0 from the endpoint), A* search is completely identical to Dijkstra's algorithm!

● Mark all nodes as gray. ● Mark the initial node s as yellow and at candidate distance 0. ● Enqueue s into the priority queue with priority 0. ● While not all nodes have been visited: ● Dequeue the lowest-cost node u from the priority queue. ● Color u green. The candidate distance d that is currently stored for node u is the length of the shortest path from s to u. ● If u is the destination node t, you have found the shortest path from s to t and are done. ● For each node v connected to u by an edge of length L: – If v is gray: ● Color v yellow. ● Mark v's distance as d + L. ● Set v's parent to be u. ● Enqueue v into the priority queue with priority d + L. – If v is yellow and the candidate distance to v is greater than d + L: ● Update v's candidate distance to be d + L. ● Update v's parent to be u. ● Update v's priority in the priority queue to d + L. Dijkstra's Algorithm

● Mark all nodes as gray. ● Mark the initial node s as yellow and at candidate distance 0. ● Enqueue s into the priority queue with priority h ( s, t ). ● While not all nodes have been visited: ● Dequeue the lowest-cost node u from the priority queue. ● Color u green. The candidate distance d that is currently stored for node u is the length of the shortest path from s to u. ● If u is the destination node t, you have found the shortest path from s to t and are done. ● For each node v connected to u by an edge of length L: – If v is gray: ● Color v yellow. ● Mark v's distance as d + L. ● Set v's parent to be u. ● Enqueue v into the priority queue with priority d + L + h(v, t). – If v is yellow and the candidate distance to v is greater than d + L: ● Update v's candidate distance to be d + L. ● Update v's parent to be u. ● Update v's priority in the priority queue to d + L + h(v, t). A* Search