Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 13 CSE 331 Sep 27, 2017.

Similar presentations


Presentation on theme: "Lecture 13 CSE 331 Sep 27, 2017."— Presentation transcript:

1 Lecture 13 CSE 331 Sep 27, 2017

2 Mini Project Pitch due in a week

3 Today’s agenda Computing Connected component (with DFS)

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

5 Why is DFS a special case of Explore?

6 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 Note that the tree is arbitrary based on which neighbor was visited first. 5 DFS tree 6 6 3 8 7

7 Questions?

8 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

9 Reading Assignment Sec 3.2 in [KT]

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

11 Stacks and Queues Last in First out First in First out
We will need to keep track of visited nodes during our traversals. First in First out

12 But first… How do we represent graphs?
When using an algorithm to solve a problem, the runtime depends on how data is organized.

13 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)

14 Questions?

15 2m = Σ u in V nu Rest of the graph Give 2 pennies to each edge
2m = Σ u in V nu Rest of the graph Give 2 pennies to each edge Total # of pennies = 2m nv=3 u nu=4 v Each edges gives one penny to its end points # of pennies u receives = nu

16 Breadth First Search (BFS)
Build layers of vertices connected to s L0 = {s} Assume L0,..,Lj have been constructed Lj+1 set of vertices not chosen yet but are connected to Lj Use CC[v] array Stop when new layer is empty Use linked lists

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


Download ppt "Lecture 13 CSE 331 Sep 27, 2017."

Similar presentations


Ads by Google