Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 19 CSE 331 Oct 13, 2010.

Similar presentations


Presentation on theme: "Lecture 19 CSE 331 Oct 13, 2010."— Presentation transcript:

1 Lecture 19 CSE 331 Oct 13, 2010

2 Online Office hours Tonight 9:30-10:30pm

3 On Friday, Oct 15 hours-a-thon Atri: 2:00-3:30 (Bell 123)
Jeff: 3:30-5:00 (Commons 9) Alex: 5:00-6:30 (Bell 224)

4 Polls on the blog In my blog post for Lect 18

5 O(m+n) BFS Implementation
Input graph as Adjacency list BFS(s) Array CC[s] = T and CC[v] = F for every v≠ u Set i = 0 Set L0= {s} While Li is not empty Linked List Li+1 = Ø For every u in Li Consider every edge (u,v) If CC[v] = F then CC[v] = T Add v to Li+1 i++

6 All layers are considered in first-in-first-out order
All the layers as one BFS(s) All layers are considered in first-in-first-out order CC[s] = T and CC[v] = F for every v≠ u Set i = 0 Set L0= {s} While Li is not empty Li+1 = Ø For every u in Li Can combine all layers into one queue: all the children of a node are added to the end of the queue For every edge (u,v) If CC[v] = F then CC[v] = T Add v to Li+1 i++

7 An illustration 1 2 3 4 5 7 8 6 1 7 2 3 8 4 5 6

8 Implementing DFS in O(m+n) time
Same as BFS except stack instead of a queue

9 Reading Assignment Sec 3.3, 3.4 and 3.5 of [KT]

10 Directed graphs Model asymmetric relationships
Precedence relationships u needs to be done before v means (u,v) edge

11 Directed graphs Adjacency matrix is not symmetric
Each vertex has two lists in Adj. list rep.

12 Directed Acyclic Graph (DAG)
No directed cycles Precedence relationships are consistent

13 Topological Sorting of a DAG
Order the vertices so that all edges go “forward”


Download ppt "Lecture 19 CSE 331 Oct 13, 2010."

Similar presentations


Ads by Google