lecture 12 - cse.buffalo.eduerdem/cse331/spring20/lectures/lect12.pdf · lecture 12 cse 331 feb21,...

9
Lecture 12 CSE 331 Feb 21, 2020

Upload: others

Post on 30-May-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 12 - cse.buffalo.eduerdem/cse331/spring20/lectures/lect12.pdf · Lecture 12 CSE 331 Feb21, 2020. Mini Project group due next Friday! 124 of you still need to do this! Connectivity

Lecture 12

CSE 331Feb 21, 2020

Page 2: Lecture 12 - cse.buffalo.eduerdem/cse331/spring20/lectures/lect12.pdf · Lecture 12 CSE 331 Feb21, 2020. Mini Project group due next Friday! 124 of you still need to do this! Connectivity

Mini Project group due next Friday!

124 of you still need to do this!

Page 3: Lecture 12 - cse.buffalo.eduerdem/cse331/spring20/lectures/lect12.pdf · Lecture 12 CSE 331 Feb21, 2020. Mini Project group due next Friday! 124 of you still need to do this! Connectivity

Connectivity Problem

Input: Graph G = (V,E) and s in V

Output: All t connected to s in G

Page 4: Lecture 12 - cse.buffalo.eduerdem/cse331/spring20/lectures/lect12.pdf · Lecture 12 CSE 331 Feb21, 2020. Mini Project group due next Friday! 124 of you still need to do this! Connectivity

Breadth First Search (BFS)

Build layers of vertices connected to s

L0 = {s}

Assume L0,..,Lj have been constructed

Lj+1 is the set of vertices not chosen yet but are connected by an edge to Lj

Stop when new layer is empty

Page 5: Lecture 12 - cse.buffalo.eduerdem/cse331/spring20/lectures/lect12.pdf · Lecture 12 CSE 331 Feb21, 2020. Mini Project group due next Friday! 124 of you still need to do this! Connectivity

BFS TreeBFS naturally defines a tree rooted at s

Lj forms the jth �level� in the tree

u in Lj+1 is child of v in Lj from which it was �discovered�

1

2 3

4 5

6

7

8

1

2 3

L0

L1

4 5 7 8 L2

6 L3

Add non-tree edges

9

0

Page 6: Lecture 12 - cse.buffalo.eduerdem/cse331/spring20/lectures/lect12.pdf · Lecture 12 CSE 331 Feb21, 2020. Mini Project group due next Friday! 124 of you still need to do this! Connectivity

Two facts about BFS trees

All non-tree edges are in the same or consecutive layer

If u is in Li then dist(s,u) = i

Page 7: Lecture 12 - cse.buffalo.eduerdem/cse331/spring20/lectures/lect12.pdf · Lecture 12 CSE 331 Feb21, 2020. Mini Project group due next Friday! 124 of you still need to do this! Connectivity

Today’s agenda

Computing Connected component

Page 8: Lecture 12 - cse.buffalo.eduerdem/cse331/spring20/lectures/lect12.pdf · Lecture 12 CSE 331 Feb21, 2020. Mini Project group due next Friday! 124 of you still need to do this! Connectivity

Computing Connected Component

Start with R = {s}

Explore(s)

While there is an edge (u,v) whereu in R and v not in R

Add v to ROutput R* = R

kobe bryantsteve nash

shaq o’neal

anthony davis

lebron james

kyrie irving

kevin love

michael jordan scottie pippen

Page 9: Lecture 12 - cse.buffalo.eduerdem/cse331/spring20/lectures/lect12.pdf · Lecture 12 CSE 331 Feb21, 2020. Mini Project group due next Friday! 124 of you still need to do this! Connectivity

Questions?