[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Labs] [More Labs] [Assignments] [Quizzes] [Examples] [Book] [Tutorial] [API]
Back to Reachability. On to Shortest Path, Revisited; Graphs, Concluded.
Held Friday, May 7
Summary
Contents
Notes
In today's class, we continued the student-led discussion of reachability and shortest-path. Some post-class notes have been added to the discussion.
By the end of yesterday's class, you'd come up with the following for your algorithm for determining whether Y is reachable from X (there is a path from X to Y).
0: boolean reachable(NodeLabel X, nodeLabel Y) 1: if there is an edge from X to Y then 2: return true 3: else 4: mark X 5: while there are unmarked neighbors of X, N 6: if reachable(N, Y) then 7: return true 08: end if 09: end for 11: // At this point, we've looked at every reasonable path 12: // from X and haven't found a way to Y. There is none. 13: return false 14: end if 13: end reachable
Evan suggested that we consider it in some more depth on something like the following example
+----------------------A8 | | | A0-----A1-----A2 A9 | |\ | A6-A7 | \ A10 | A4--A3 | | A5-------+
reachable(A0,A9)
?
reachable(A0,A9) 1: There is not an edge from A0 to A9 4: A0 is marked 5: A1 is an unmarked neighbor 6: Call reachable(A1,A9) and wait for result reachable(A1,A9) 1. There is not an edge from A1 to A9 4: A1 is now marked 5: A2 is an unmarked neighbor of A1 6: Call reachable(A2,A9) and wait for result reachable(A2,A9) 1. There is not an edge from A2 to A9 4. A2 is now marked 5. There are no unmarked neighbors of A2 13. Returns false 6. The recursive call failed. 9. Go back to the top of the loop 5. A10 is an unmarked neighbor of A1 6: Call reachable(A10,A9) and wait for result reachable(A10,A9) 1. There is not an edge from A10 to A9 4. A10 is now marked 5. There are no unmarked neighbors of A10 13. Returns false 6. The recursive call failed. 9. Go back to the top of the loop 5. There are no unmarked neighbors of A1 13. Return false 6. The recursive call failed. 9. Go back to the top of the loop 5. A3 is an unmarked neighbor of A0. 6. Call reachable(A3,A9) and wait for result reachable(A3,A9) 1. There is not an edge from A3 to A9 5. A4 is an unmarked neighbor of A3 6: Call reachable(A4,A9) and wait for result reachable(A4,A9) 1. There is not an edge from A4 to A9 4. A4 is now marked 5. There are no unmarked neighbors of A4 13. Returns false 6. The recursive call failed. 9. Go back to the top of the loop 5. A5 is an unmarked neighbor of A3 6: Call reachable(A5,A9) and wait for result reachable(A5,A9) 1. There is not an edge from A5 to A9 4. A5 is now marked 5. A6 is an unmarked neighbor of A5 6. Call reachable(A6,A9) and wait for result reachable(A6,A9) 1. There is not an edge from A6 to A9 4. A6 is now marked 5. A7 is an unmarked neighbor of A5 6. Call reachable(A7,A9) and wait for result reachable(A7,A9) 1. There is not an edge from A7 to A9 4. A7 is now marked 5. There are no unmarked neighbors of A7 13. Returns false 6. The recursive call failed. 9. Go back to the top of the loop 5. A8 is an unmarked neighbor of A5 6. Call reachable(A8,A9) and wait for result reachable(A8,A9) 1. There is an edge from A8 to A9 2. Returns true 6. The recusive call succeeded 7. Returns true 6. The recusive call succeeded 7. Returns true 6. The recusive call succeeded 7. Returns true 6. The recusive call succeeded 7. Returns true
The loop terminates because it scans through unmarked nodes, and recursive calls either mark nodes or return true (in which case the loop also terminates). Since there are only a finite number of nodes, we'll eventually mark them all or return true.
Our particular algorithm determines whether there is a path from X to Y using only unmarked nodes.
History
Back to Reachability. On to Shortest Path, Revisited; Graphs, Concluded.
[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Labs] [More Labs] [Assignments] [Quizzes] [Examples] [Book] [Tutorial] [API]
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS152/99S/Outlines/outline.52.html
Source text last modified Sun May 9 09:53:06 1999.
This page generated on Sun May 9 09:59:40 1999 by SiteWeaver. Validate this page's HTML.
Contact our webmaster at rebelsky@math.grin.edu