Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| courses:cs211:winter2018:journals:martinj:3.2.6 [2018/02/07 04:07] – martinj | courses:cs211:winter2018:journals:martinj:3.2.6 [2018/02/07 04:55] (current) – martinj | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| ===== Brief summary | ===== Brief summary | ||
| - | 3.2 covered graph connectivity and graph traversal, including breadth-first and depth-first searches, which determine s-t connectivity, | + | 3.2 covered graph connectivity and graph traversal, including breadth-first and depth-first searches, which determine s-t connectivity, |
| - | + | ||
| - | ===== Motivations ===== | + | |
| ===== Algorithms: brief sketches, intuitions, implementations, | ===== Algorithms: brief sketches, intuitions, implementations, | ||
| ==== Breadth-First Search ==== | ==== Breadth-First Search ==== | ||
| Line 16: | Line 14: | ||
| * There is a path from s to t IFF t appears in some layer | * There is a path from s to t IFF t appears in some layer | ||
| * If there is an edge between two points in the original graph, then those two points differ by at most 1 in the breadth-first search tree | * If there is an edge between two points in the original graph, then those two points differ by at most 1 in the breadth-first search tree | ||
| - | + | Worst-case runtime: O(# of vertices) | |
| - | + | === Depth-First Search | |
| - | + | General concept: start from s and try the first edge leading out. Continue this process until you reach a "dead end" | |
| - | ===== Questions ===== | + | Pseudocode: |
| + | DFS(u): | ||
| + | Mark u as " | ||
| + | For each edge (u,v) incedent to u | ||
| + | If v is not marked " | ||
| + | Recursively invoke DFS(v) | ||
| + | Endif | ||
| + | Endfor | ||
| + | Concepts: | ||
| + | * Node m is an ancestor of node n if n was marked as explored after m (I think) | ||
| + | * If x & y are two nodes that are connected by an edge in the original graph, but not connected its BFS tree, one of them is an ancestor of the other | ||
| ===== Stuff I want to remember ===== | ===== Stuff I want to remember ===== | ||
| - | + | There are 2 basic ways to represent graphs: | |
| - | ===== How readable / interesting | + | - An adjacency matrix -- requires O(n^2 ) space |
| + | - An adjacency list representation -- requires only O(m+n) space | ||
| + | A queue is a set form which we extract elements in FIFO (first in, first out) order = the order in which they were added | ||
| + | * Stack = same, but opposite (LIFO) | ||
