210 likes | 339 Views
Lecture 15. CSE 331 Oct 3, 2011. Mid term. Next Monday in class. Unfortunately I won’t be there. Jiun-Jie with my PhD students Steve & Swapnoneel will proctor the exam. Feedback Response-I. I’ll use the microphone today. Let me know via poll on the blog if it worked better.
E N D
Lecture 15 CSE 331 Oct 3, 2011
Mid term Next Monday in class Unfortunately I won’t be there Jiun-Jie with my PhD students Steve & Swapnoneel will proctor the exam
Feedback Response-I I’ll use the microphone today Let me know via poll on the blog if it worked better
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
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
Mid term entry Has been posted on the blog Don’t read too much into the content of the sample mid-term
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)
Graph representations 1 0 1 0 1 0 Better for sparse graphs and traversals 0 1 0 Adjacency matrix Adjacency List O(1) O(n) [ O(nv) ] (u,v) in E? All neighbors of u? O(n) O(nu) O(n2) Space? O(m+n)
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 v nu=4 u Each edges gives one penny to its end points # of pennies u receives = nu
Today’s agenda Run-time analysis of BFS
Breadth First Search (BFS) Build layers of vertices connected to s L0= {s} Assume L0,..,Ljhave been constructed Lj+1set of vertices not chosen yet but are connected to Lj Stop when new layer is empty Use CC[v] array Use linked lists
An illustration 1 2 3 4 5 7 8 6 1 7 2 3 8 4 5 6
Implementing DFS in O(m+n) time Same as BFS except stack instead of a queue
A DFS run using an explicit stack 7 8 1 7 6 7 3 2 3 5 8 4 4 5 5 3 6 2 3 1
Reading Assignment Sec 3.3, 3.4 and 3.5 of [KT]
Directed graphs Model asymmetric relationships Precedence relationships u needs to be done before v means (u,v) edge
Directed graphs Adjacency matrix is not symmetric Each vertex has two lists in Adj. list rep.
Directed Acyclic Graph (DAG) No directed cycles Precedence relationships are consistent
Topological Sorting of a DAG Order the vertices so that all edges go “forward”