cse101-w12-graphs-dfs-dags-final

cse101-w12-graphs-dfs-dags-final - CSE 101, Winter 2012...

Info iconThis preview shows pages 1–16. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE 101, Winter 2012 Design and Analysis of Algorithms Lecture 2: Graphs, DFS (Undirected, Directed), DAGs Class URL: http://vlsicad.ucsd.edu/courses/cse101-w12/
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Graphs Internet topology
Background image of page 2
Graphs Human known protein interactions
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Graphs Adjacency graph of chromosomes in yeast Example musing: What is the relationship between folding in 3D brain structure, and neural connectivity?
Background image of page 4
Graphs Connection of macaque retinal ganglion cells to {long, medium, short}-wavelength cone receptors Example musing: What “objective function” is being optimized by Mother Nature?
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Graphs Gene-gene interactions affecting phenotype in yeast
Background image of page 6
Graphs Airline routes System dependence graph
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Graph Representation How is this stored in a computer? • Graph G = (V,E) – Vertex set V = V(G) – Edge set E = E(G) (connecting pairs of vertices) 1 2 3 4 5
Background image of page 8
Graph Representation • Adjacency Matrix • Graph G = (V,E) – Vertex set V = V(G) – Edge set E = E(G) (connecting pairs of vertices) 1 2 3 4 5 0 1 1 1 0 5 1 0 0 0 1 4 1 0 0 1 1 3 1 0 1 0 0 2 0 1 1 0 0 1 5 4 3 2 1 O(|V| 2 ) storage needed
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Graph Representation • Adjacency Matrix • Graph G = (V,E) – Vertex set V = V(G) – Edge set E = E(G) (connecting pairs of vertices) 1 2 3 4 5 0 1 1 1 0 5 1 0 0 0 1 4 1 0 0 1 1 3 1 0 1 0 0 2 0 1 1 0 0 1 5 4 3 2 1 O(|V| 2 ) storage needed • Adjacency List 1 2 3 4 5 3 3 4 1 1 2 5 2 5 5 3 4 O(|V| + |E|) storage needed
Background image of page 10
Depth-First Search Depth-first search is a method for exploring a graph – Explore “deeper” in the graph whenever possible – Edges are explored out of the most recently discovered vertex v that still has unexplored edges – When all of v ’s edges have been explored, backtrack to the vertex from which v was discovered • Analogy: Exploring a maze – Mark with chalk: has the vertex been visited already – Unwind / rewind ball of string: stack push / pop – Pseudocode in book: stack is implicit from recursion
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Depth-First Search: Code Figure 3.3 Finding all nodes reachable from a particular node. procedure explore(G,v) Input: G = (V,E); v V Output: visited(u) set to true for all nodes u reachable from v visited(v) = true previsit(v) // pre[v] = clock; clock++; for each edge (v,u) in E: if not visited(u): explore(u) postvisit(v) // post[v] = clock; clock++; A B E I J A B E I J 1,10 2,3 4,9 5,8 6,7
Background image of page 12
Depth-First Search: Code Figure 3.3 Finding all nodes reachable from a particular node. procedure explore(G,v) Input: G = (V,E); v V Output: visited(u) set to true for all nodes u reachable from v visited(v) = true previsit(v) // pre[v] = clock; clock++; ccnum[v] = cc for each edge (v,u) in E: if not visited(u): explore(u) postvisit(v) // post[v] = clock; clock++; Figure 3.5 Depth-first search. procedure dfs (G) // clock = 1; cc = 0; for all v V: visited(v) = false for all v V: if not visited(v): cc++; explore(v)
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Depth-First Search: Example (Fig. 3.6) A B E F I J C D G H K L A B E I J C D H G L K F 1,10 2,3 4,9 5,8 6,7 CC1 CC2 CC3 11,22 12,21 13,20 14,17 15,16 18,19 23,24 Tree edge: when encountering a new vertex Back edge: when encountering a previously-seen vertex (i.e., from descendant to ancestor)
Background image of page 14
Depth-First Search: Notes • pre[v] is the step when a vertex is first touched, and post[v] is the step when a vertex is last touched – Correspond to preorder and
Background image of page 15

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 16
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 40

cse101-w12-graphs-dfs-dags-final - CSE 101, Winter 2012...

This preview shows document pages 1 - 16. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online