Lecture 14 CSE 331 Oct 5, 2009 Extra lectures on proofs Tuesday 5-6pm (Jeff) Wednesday 4:30-6pm (Atri) Commons 9 Prefer my name to Professor/Dr. Rudra Next Week I will be out of town Mon+Wed lecture by Hung Ngo Mid-term Scribe needed for Wed Proctored by Hung and couple of Ph.D. students Sample mid-term will be handed out on Friday Jeff’s recitations Flat tire today A BFS run L0 = {s} Assume L0,..,Lj have been constructed Lj+1 set of vertices not chosen yet but are connected to Lj Stop when new layer is empty 1 2 7 L0 1 2 3 L1 3 8 4 5 6 4 5 6 7 8 L2 L3 A DFS run DFS(u) u is explored 1 1 7 For every unexplored neighbor v of u 2 2 3 DFS(v) 8 4 4 5 5 6 6 3 8 7 Today’s agenda Run-time analysis of BFS (DFS) Stacks and Queues Last in First out First in First out Graph representations 0 1 1 1 0 0 1 0 0 Better for sparse graphs and traversals Adjacency matrix O(1) Adjacency List (u,v) in E? O(n) [ O(nv) ] O(n) All neighbors of u? O(nu) O(n2) Space? O(m+n)