Download presentation
Presentation is loading. Please wait.
1
Lecture 15 CSE 331 Oct 5, 2012
2
HW 4 due today I will not take any HW after 1:15pm
Q1, Q2 and Q3 in different piles I will not take any HW after 1:15pm
3
Other HW related stuff HW 5 has been posted online: see blog/piazza
Solutions to HW 4 at the END of the lecture Graded HW 3: pickup from TAs next week
4
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)
5
HW 4 due today I will not take any HW after 1:15pm
Q1, Q2 and Q3 in different piles I will not take any HW after 1:15pm
6
Questions?
7
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
8
Today’s agenda Run-time analysis of BFS
9
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
10
An illustration 1 2 3 4 5 7 8 6 1 7 2 3 8 4 5 6
11
Implementing DFS in O(m+n) time
Same as BFS except stack instead of a queue
12
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
13
Reading Assignment Sec 3.3, 3.4 and 3.5 of [KT]
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.