21
CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License . es by: Eric Ringger, adapting figures from Dasgupta et al.

CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported

Embed Size (px)

Citation preview

Page 1: CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported

CS 312: Algorithm Design & Analysis

Lecture #17: Connectedness in Graphs

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.

Slides by: Eric Ringger, adapting figures from Dasgupta et al.

Page 2: CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported

Announcements

Due now: HW #13

Project #4 Wednesday: Whiteboard Experience Friday: Early Day Virtual Monday = Tuesday: Due

Technical Career Fair: Thursday 9am-3pm in Wilkinson Student Center Preview: Wednesday 4:00pm in 1170 TMCB

This Week According to schedule!

Page 3: CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported

Objectives

Wrap up connectedness in Undirected Graphs

DFS on Directed Graphs

Understand how to linearize a DAG

Page 4: CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported

Many Kinds of Connectedness

Page 5: CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported

DFS Analysis

“Non-committal Case”:Our generic analysis

covers best and worstcases.

Page 6: CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported

DFS Yields a Forest

Page 7: CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported

Directed Graphs

Let’s switch gears to directed graphs now

Page 8: CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported

DFS on Directed Graphs

Page 9: CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported

DFS on Directed Graphs

Page 10: CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported

Edge Types Tree edges: part of the DFS

forest

Forward edges: lead to a non-child descendant in the DFS tree.

Back edges: lead to an ancestor in the DFS tree.

Cross edges: lead to a node that has already been completely explored (that is, already post-visited) lead to neither descendant nor

ancestor

Page 11: CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported

Classifying Edge Types

Pre Pre Post Post

?

Page 12: CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported

Classifying Edge Types

Pre Pre Post Post

Page 13: CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported

Classifying Edge Types

Pre Pre Post Post

?

Page 14: CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported

Classifying Edge Types

Pre Pre Post Post

Page 15: CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported

Classifying Edge Types

Pre Pre Post Post

< ?

Page 16: CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported

Classifying Edge Types

Pre Pre Post Post

<

Page 17: CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported

Classify Edge

Page 18: CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported

Cycles

How do you detect a cycle in a directed graph?

Property: A directed graph has a cycle if and only if its depth-first search reveals a back edge.

Otherwise: a Directed Acyclic Graph (DAG)

Page 19: CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported

Sources, Sinks, LinearizationDFS Search Forest:

Linearization of the DAG == Topological Ordering of the DAG:

0. Define order; 1. DFS; 2. Read off post-order values in reverse order

Analysis:

Input DAG:

Page 20: CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported

Sources, Sinks, Linearization

In our DAG, what do you notice about sources, sinks and post-order numbers?

Page 21: CS 312: Algorithm Design & Analysis Lecture #17: Connectedness in Graphs This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported

Assignment

HW 13.5

Whiteboard Experience for Project #4