Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| courses:cs211:winter2014:journals:emily:entrythree [2014/01/29 02:06] – [Chapter 3.3] hardye | courses:cs211:winter2014:journals:emily:entrythree [2014/02/10 18:42] (current) – [Depth-First Search] hardye | ||
|---|---|---|---|
| Line 39: | Line 39: | ||
| This search is exploring the nodes outward in all possible directions, //layer by layer//. Layer L< | This search is exploring the nodes outward in all possible directions, //layer by layer//. Layer L< | ||
| - | **Fact**\\ | + | === Fact === |
| For each i>=1, layer L< | For each i>=1, layer L< | ||
| BFS produces a tree whose root is node s. \\ | BFS produces a tree whose root is node s. \\ | ||
| - | **Theorem**\\ | + | |
| + | === Theorem | ||
| Let T be a BFS tree, let x and y be nodes in T belonging to layers L< | Let T be a BFS tree, let x and y be nodes in T belonging to layers L< | ||
| To explore a connected component we refer to the set R of nodes that are reachable from s. | To explore a connected component we refer to the set R of nodes that are reachable from s. | ||
| - | **Algorithm** | + | === Algorithm |
| R will consist of nodes to which s has a path | R will consist of nodes to which s has a path | ||
| Initially R = {s} | Initially R = {s} | ||
| Line 57: | Line 57: | ||
| Endwhile | Endwhile | ||
| - | **Theorem 3.5** | + | |
| + | === Theorem 3.5 === | ||
| The set R produced at the end of the algorithm is precisely the connected component of G containing s. | The set R produced at the end of the algorithm is precisely the connected component of G containing s. | ||
| Line 63: | Line 64: | ||
| This method of searching explores a graph by going as deeply as possible and only retreating when necessary. | This method of searching explores a graph by going as deeply as possible and only retreating when necessary. | ||
| - | **Algorithm** | + | ==== Algorithm |
| DFS(u): | DFS(u): | ||
| mark u as " | mark u as " | ||
| Line 74: | Line 75: | ||
| BFS is similar in that it builds the connected component containing s and they achieve the same level of efficiency. But DFS visits the same number of nodes in a completely different order. DFS trees have a greater height and are narrower. | BFS is similar in that it builds the connected component containing s and they achieve the same level of efficiency. But DFS visits the same number of nodes in a completely different order. DFS trees have a greater height and are narrower. | ||
| - | **Theorem** | + | ==== Theorem |
| For a given recessive call DFS(u), all nodes that are marked " | For a given recessive call DFS(u), all nodes that are marked " | ||
| with this we can prove: | with this we can prove: | ||
| - | **Theorem 3.7** | + | ==== Theorem 3.7 ==== |
| Let T be a depth first search tree, let x and y be nodes in T, and let (x,y) be an edge of G that is not an edge of T. Then one of x or y is an ancestor of the other. | Let T be a depth first search tree, let x and y be nodes in T, and let (x,y) be an edge of G that is not an edge of T. Then one of x or y is an ancestor of the other. | ||
