Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
courses:cs211:winter2012:journals:ian:chapter3 [2012/01/31 23:38] – sturdyi | courses:cs211:winter2012:journals:ian:chapter3 [2012/02/01 03:11] (current) – sturdyi | ||
---|---|---|---|
Line 4: | Line 4: | ||
* A graph is a connection of nodes and edges, which may be either directed or undirected; this can model a variety of complexes and relationships, | * A graph is a connection of nodes and edges, which may be either directed or undirected; this can model a variety of complexes and relationships, | ||
- | | + | |
+ | * No questions. | ||
+ | * No other complaints. 7/10. | ||
===== 3.2 Graph Connectivity and Traversal ===== | ===== 3.2 Graph Connectivity and Traversal ===== | ||
- | * Two common patterns to algorithms answering questions about graphs are breadth-first and depth-first search; the former is particularly useful for finding shortest roots and analyzing cycles, and the latter where backtracking is easier than arbitrary jumping; both are suited to finding connected components. | + | |
+ | * Two common patterns to algorithms answering questions about graphs are breadth-first and depth-first search; the former is particularly useful for finding shortest roots and analyzing cycles, and the latter where backtracking is easier than arbitrary jumping; both are suited to finding connected components. In BFS two nodes sharing an edge must be in the same layer or subsequent layers; in DFS if {// | ||
+ | * No insights. | ||
+ | * No questions. | ||
+ | * No complaints.. 7/10. | ||
===== 3.3 Implementing Graph Traversal Using Queues and Stacks ===== | ===== 3.3 Implementing Graph Traversal Using Queues and Stacks ===== | ||
+ | |||
* BFS and DFS have a relationship analogous to that between queues and stacks. Both can be implemented in two-parameter linear time, O(m+n) (assuming a graph represented as an adjacency list, the most efficient for most operations on sparse graphs). For BFS, at each layer, find all the not-yet discovered nodes connected to the layer under consideration, | * BFS and DFS have a relationship analogous to that between queues and stacks. Both can be implemented in two-parameter linear time, O(m+n) (assuming a graph represented as an adjacency list, the most efficient for most operations on sparse graphs). For BFS, at each layer, find all the not-yet discovered nodes connected to the layer under consideration, | ||
* No insights. | * No insights. | ||
Line 16: | Line 23: | ||
===== 3.4 Testing Bipartiteness: | ===== 3.4 Testing Bipartiteness: | ||
+ | |||
+ | * A bipartite graph is one in which the nodes can be divided into two sets such that no edge joins two members of the same set; alternatively (and equivalently), | ||
+ | * No insights. | ||
+ | * No questions. | ||
+ | * I think the proof of correctness somewhat circuitous--the algorithm not only proves bipartiteness but produces a colouring, and it seems easy to show that the colouring is valid. This whole business of odd cycles is itself fascinating, | ||
+ | |||
+ | ===== 3.5 Connectivity in Directed Graphs ===== | ||
+ | |||
+ | * Directed graphs can use an expanded adjacency list representation, | ||
+ | * No insights. | ||
+ | * No questions. | ||
+ | * No complaints. 7/10. | ||
+ | |||
+ | ===== 3.6 Directed Acyclic Graphs and Topological Ordering ===== | ||
+ | |||
+ | * DAGs appear in such contexts as dependency networks (at least one hopes that one's dependencies are acyclic). a topological ordering of a DAG is an ordering of the nodes such that every edge connects nodes in order. For directed graphs, acyclicality is equivalent to the existence of a topological ordering. Every DAG must have a node with no incoming edges; recursive application of this fact yields a topological ordering. This can be done in O(m+n) time by keeping an array of the number of incoming connections to each node and then, whenever adding a node to the ordering, decrementing that number for each of the nodes to which it leads. | ||
+ | * I had been wondering how to do this in conceptual work for a project I shall probably never get to (applying parallelization and large-dataset techniques (as discussed yesterday) to econometrics)--I am consistently impressed at how elegant some of these solutions are. | ||
+ | * Does not the O(m+n) runtime of the algorithm depend on being able to select an edge with no remaining ancestors in constant time? If it involves a scan through the array of remaining parents, I would think that the inner loop would be O(n^2), since it must repeat once for each node and each step is O(n) on account of the scan. | ||
+ | * Well written. 8/10. |