/
CSE 421 Algorithms   Autumn 2019 CSE 421 Algorithms   Autumn 2019

CSE 421 Algorithms Autumn 2019 - PowerPoint Presentation

shoffer
shoffer . @shoffer
Follow
342 views
Uploaded On 2020-06-22

CSE 421 Algorithms Autumn 2019 - PPT Presentation

Lecture 6 Announcements Reading Start on Chapter 4 Graph Theory G V E V vertices V n E edges E m Undirected graphs Edges sets of two vertices u v Directed graphs Edges ordered pairs u v ID: 783534

search vertex graph vertices vertex search vertices graph edge edges degree connected topological graphs find cycle sort components unvisited

Share:

Link:

Embed:

Download Presentation from below link

Download The PPT/PDF document "CSE 421 Algorithms Autumn 2019" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

CSE 421Algorithms

Autumn 2019

Lecture 6

Slide2

Announcements

Reading

Start on Chapter 4

Slide3

Graph Theory

G = (V, E)

V: vertices, |V|= n

E: edges, |E| = m

Undirected graphs

Edges sets of two vertices {u, v}Directed graphsEdges ordered pairs (u, v)Many other flavorsEdge / vertices weightsParallel edgesSelf loops

Path: v1, v2, …, vk, with (vi, vi+1) in ESimple PathCycleSimple CycleNeighborhoodN(v)DistanceConnectivityUndirectedDirected (strong connectivity)TreesRootedUnrooted

Explain that there will be some review from 326

By default |V| = n and |E| = m

Slide4

Last Lecture

Bipartite Graphs : two-colorable graphs

Breadth First Search algorithm for testing two-

colorability

Two-colorable

iff no odd length cycleBFS has cross edge iff graph has odd cycle

Slide5

Graph Search

Data structure for next vertex to visit determines search order

Slide6

Graph search

Breadth First Search

S

= {s

}

while S is not empty

u = Dequeue(S) if u is unvisited visit u foreach v in N(u) Enqueue(S, v)

Depth First Search S = {s} while S is not empty u = Pop(S) if u is unvisited

visit u

foreach

v in N(u)

Push(S, v)

Slide7

Breadth First Search

All edges go between vertices on the same layer or adjacent layers

2

8

3

7

6

5

4

1

Slide8

Depth First Search

Each edge goes between vertices on the same branch

No cross edges

1

2

5

6

12

7

4

3

8

9

10

11

Slide9

Connected Components

Undirected Graphs

Slide10

Computing Connected Components in O(n+m) time

A search algorithm from a vertex v can find all vertices in v’s component

While there is an unvisited vertex v, search from v to find a new component

Slide11

Directed Graphs

A Strongly Connected Component is a subset of the vertices with paths between every pair of vertices.

Slide12

Identify the Strongly Connected Components

Slide13

Strongly connected components can be found in O(n+m) time

But it’s tricky!

Simpler problem: given a vertex v, compute the vertices in v’s scc in O(n+m) time

Slide14

Topological Sort

Given a set of tasks with precedence constraints, find a linear order of the tasks

142

143

311

341

351

333

332

312

431

421

451

Slide15

Find a topological order for the following graph

E

F

D

A

C

B

K

J

G

H

I

L

Slide16

If a graph has a cycle, there is no topological sort

Consider the first vertex on the cycle in the topological sort

It must have an incoming edge

B

A

D

E

F

C

Definition: A graph is Acyclic if it has no cycles

Slide17

Lemma: If a

(finite)

graph is acyclic, it has a vertex with in-degree 0

Proof:

Pick a vertex v

1, if it has in-degree 0 then doneIf not, let (v2, v1) be an edge, if v2 has in-degree 0 then doneIf not, let (v3, v2) be an edge . . .

If this process continues for more than n steps, we have a repeated vertex, so we have a cycle

Slide18

Topological Sort Algorithm

While there exists a vertex v with in-degree 0

Output vertex v

Delete the vertex v and all out going edges

E

F

D

A

C

B

K

J

G

H

I

L

Slide19

Details for O(n+m) implementation

Maintain a list of vertices of in-degree 0

Each vertex keeps track of its in-degree

Update in-degrees and list when edges are removed

m edge removals at O(1) cost each