





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!






MIT OpenCourseWare http://ocw.mit.edu
Spring 2008 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.
Lecture 12: Searching I: Graph Search and Representations
Explore a graph e.g., find a path from start vertices to a desired vertex Recall: graph G = (V, E)
Figure 1: Example to illustrate graph terminology
“Geography” of configuration graph
... “breadth- first tree” possible first moves reachable in two steps but not one Figure 4: Breadth-First Tree � reachable configurations distance 90 ◦^ turns 90 ◦^ & 180 ◦^ turns 0 1 1 1 6 9 2 27 54 3 120 321 4 534 1, 5 2,256 9, 6 8,969 50, 7 33,058 227, 8 114,149 870, 9 360,508 1,887, 10 930,588 623, 11 1,350,852 2,644 ←diameter 12 782, 13 90, 14 276 ←diameter 3,674,160 3,674, Wikipedia Pocket Cube Cf. 3 × 3 × 3 Rubik’s cube: ≈ 1. 4 trillion states; diameter is unknown! ≤ 26
Figure 6: Edge Representation Representing Graphs: contd. The above representations are good for for sparse graphs where | E |� (| V |)^2. This translates to a space requirement = Θ(V + E) (Don’t bother with |. | ’s inside O/Θ). Adjacency Matrix:
a b c A =
0 0 1 1 0 1 0 1 0 1 2 3 1 2 3 Figure 7: Matrix Representation
Implicit Graphs: Adj(u) is a function or u.neighbors/edges is a method =⇒ “no space” (just what you need now)
Breadth-first search Levels like “geography”
... frontier s Figure 8: Illustrating Breadth-First Search