Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 15 CSE 331 Oct 3, 2011.

Similar presentations


Presentation on theme: "Lecture 15 CSE 331 Oct 3, 2011."— Presentation transcript:

1 Lecture 15 CSE 331 Oct 3, 2011

2 Mid term Next Monday in class Unfortunately I won’t be there
Jiun-Jie with my PhD students Steve & Swapnoneel will proctor the exam

3 Feedback Response-I I’ll use the microphone today
Let me know via poll on the blog if it worked better

4 Graphs will help us here
Feedback Response-II Problem Statement Real world problem Graphs will help us here Problem Definition Precise mathematical def Algorithm “Implementation” Data Structures Analysis Correctness/Run time

5 Feedback Response-III
The workload is “insane” and I might be unaware of it Syllabus states that you’re supposed to spend at least 8-12 hours outside of the lectures If you’re spending much more time than above, please come and talk to me I’m aware that ideal situations do not always exists More chances for you to “make-up” in the course

6 Mid term entry Has been posted on the blog
Don’t read too much into the content of the sample mid-term

7 On Friday, Oct 7 hours-a-thon Atri: 2:00-3:00 (Bell 123)
Jiun-Jie: 4:00-5:00 (Commons 9) Jesse: 5:00-6:00 (Bell 224)

8 Empty Slots Coming up…

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

10 2 # edges = sum of # neighbors
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

11 Questions?

12 Today’s agenda Run-time analysis of BFS

13 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

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

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

16 A DFS run using an explicit stack
7 8 1 7 7 6 3 2 3 5 8 4 4 5 5 3 6 2 3 1

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

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

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

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

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


Download ppt "Lecture 15 CSE 331 Oct 3, 2011."

Similar presentations


Ads by Google