lecture 17 cse 331 oct 8, 2010. hw 4 due today q1 and q2 in one pile q3 in another pile i will not...

16
Lecture 17 CSE 331 Oct 8, 2010

Post on 21-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Lecture 17

CSE 331Oct 8, 2010

HW 4 due today

Q1 and Q2 in one pile

Q3 in another pile

I will not take any HW after 1:15pm

Solutions to HW 4+ graded HW 3

At the end of the lecture

HW 5

Has been posted

Sample mid term

Has been posted: a blog post soon

Don’t read too much into the content

On Friday, Oct 15

hours-a-thon

Atri: 2:00-3:30 (Bell 123)

Jeff: 3:30-5:00 (Commons 9)Alex: 5:00-6:30 (Bell 224)

A theory workshop this weekend

http://www.cse.buffalo.edu/events/theory-III/

DFS(u)

u is explored

For every unexploredneighbor v of u

DFS(v)

A DFS run

11

22 33

44 55

66

77

88

11

22

44

55

66 33

88

77

Every non-tree edge is between a

node and its ancestor

Every non-tree edge is between a

node and its ancestor

DFS treeDFS tree

HW 4 due today

Q1 and Q2 in one pile

Q3 in another pile

I will not take any HW after 1:15pm

Questions?

Connected components are disjoint

Either Connected components of s and t are the same or are disjoint

Algorithm to compute ALL the connected

components?

Algorithm to compute ALL the connected

components?

Run BFS on some node s. Then run BFS on t that is not connected to s Run BFS on some node s. Then run BFS on t that is not connected to s

Today’s agenda

Run-time analysis of BFS (DFS)

Stacks and Queues

Last in First out

First in First out

But first…

How do we represent graphs?

Graph representations

Adjacency matrix

0

1

1

1

0

0

1

0

0

Adjacency List

(u,v) in E?O(1) O(n) [ O(nv) ]

All neighbors of u?O(n) O(nu)

Space?O(n2) O(m+n)

Better for sparse graphs and traversals

Better for sparse graphs and traversals

m ≤ n(n-1)/2: why?