Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 14 CSE 331 Oct 3, 2012.

Similar presentations


Presentation on theme: "Lecture 14 CSE 331 Oct 3, 2012."— Presentation transcript:

1 Lecture 14 CSE 331 Oct 3, 2012

2 Online OH

3 Zihe’s makeup recitation

4 Computing Connected Component
Explore(s) Start with R = {s} While exists (u,v) edge v not in R and u in R Add v to R Output R

5 Explore(s) = Connected Comp.(s)
Lemma 1: If w is in R then s is connected to w Lemma 2: If s is connected to w then w is in R

6 Questions?

7 BFS all

8 Depth First Search (DFS)

9 DFS(u) Mark u as explored and add u to R For each edge (u,v)
If v is not explored then DFS(v)

10 Why is DFS a special case of Explore?

11 Every non-tree edge is between a node and its ancestor
A DFS run Every non-tree edge is between a node and its ancestor DFS(u) u is explored For every unexplored neighbor v of u DFS(v) 1 1 7 2 2 3 8 4 4 5 5 DFS tree 6 6 3 8 7

12 Questions?

13 Connected components are disjoint
Either Connected components of s and t are the same or are disjoint Algorithm to compute ALL the connected components? Run BFS on some node s. Then run BFS on t that is not connected to s

14 Reading Assignment Sec 3.2 in [KT]

15 Rest of today’s agenda Run-time analysis of BFS (DFS)

16 Stacks and Queues Last in First out First in First out

17 But first… How do we represent graphs?

18 Graph representations
1 Better for sparse graphs and traversals Adjacency matrix Adjacency List (u,v) in E? O(1) O(n) [ O(nv) ] All neighbors of u? O(n) O(nu) O(n2) Space? O(m+n)


Download ppt "Lecture 14 CSE 331 Oct 3, 2012."

Similar presentations


Ads by Google