48
Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Embed Size (px)

Citation preview

Page 1: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Lecture 5.4: Paths and Connectivity

CS 250, Discrete Structures, Fall 2011

Nitesh Saxena

*Adopted from previous lectures by Zeph Grunschlag

Page 2: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Course Admin -- Homework 5 Due at 11am on Nov 30 (Wed) Covers the chapter on Graphs (lecture

5.*) Thanksgiving is in the way – please try

to start early Has a 10-pointer bonus problem too

Lecture 5.4 -- Paths and Connectivity

Little work will not hurt!

Page 3: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Course Admin -- Homework 4

Grading now Expect results in a couple of days Graded HWs will be distributed next

Tuesday Solution posted

Lecture 5.4 -- Paths and Connectivity

Page 4: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Course Admin -- Final Exam Thursday, December 8,  10:45am-

1:15pm, lecture room Heads up! Please mark the date/time/place Emphasis on post mid-term 2 material Coverage:

65% post mid-term 2 (lectures 4.*, 5.*, 6.*), and 35% pre mid-term 2 (lecture 1.*. 2.* and 3.*)

Our last lecture will be on December 6 We plan to do a final exam review then

Lecture 5.4 -- Paths and Connectivity

Page 5: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Lecture 5.4 -- Paths and Connectivity

Outline

Paths and Isomorphism Connectivity

Page 6: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

A visualization of the Linkein Social Graph

Lecture 5.4 -- Paths and Connectivity

Page 7: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

and of the Facebook network

Lecture 5.4 -- Paths and Connectivity

Page 8: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Recap: Graph Isomorphism

DEF: Suppose G1 = (V1, E1 ) and G2 = (V2, E2 ) are pseudographs. Let f :V1V2 be a function s.t.:

1) f is bijective2) for all vertices u,v in V1, the number of

edges between u and v in G1 is the same as the number of edges between f (u) and f (v ) in G2; or e(u, v, G1) = e(f(u), f(v), G2)

Then f is called an isomorphism and G1 is said to be isomorphic to G2.Lecture 5.4 -- Paths and

Connectivity

Page 9: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Properties of IsomorphismsTwo graphs are isomorphic to each other if they satisfy the following properties:same number of verticessame number of edgessame degrees at corresponding verticesAny subgraph of one is isomorphic to some subgraph of the other

Lecture 5.4 -- Paths and Connectivity

Page 10: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Warm-up Exercise

Theorem: Isomorphism is an equivalence relationProof: We need to prove that the isomorphism relation is reflexive, symmetric, and transitive.

Let’s use the whiteboard.

Lecture 5.4 -- Paths and Connectivity

Page 11: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Paths

A path in a graph is a continuous way of getting from one vertex to another by using a sequence of edges.

EG: could get from 1 to 3 circuitously as follows:

1-e12-e11-e33-e42-e62-e52-e43

1 2

3 4

e1

e3

e2

e4e5

e6

e7

Page 12: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Paths

1

A path in a graph is a continuous way of getting from one vertex to another by using a sequence of edges.

EG: could get from 1 to 3 circuitously as follows:

1-e12-e11-e33-e42-e62-e52-e43

2

3 4

e1

e3

e2

e4e5

e6

e7

Page 13: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Paths

A path in a graph is a continuous way of getting from one vertex to another by using a sequence of edges.

EG: could get from 1 to 3 circuitously as follows:

1-e12-e11-e33-e42-e62-e52-e43

1 2

3 4

e1

e3

e2

e4e5

e6

e7

Page 14: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Paths

A path in a graph is a continuous way of getting from one vertex to another by using a sequence of edges.

EG: could get from 1 to 3 circuitously as follows:

1-e12-e11-e33-e42-e62-e52-e43

1 2

3 4

e1

e3

e2

e4e5

e6

e7

Page 15: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Paths

A path in a graph is a continuous way of getting from one vertex to another by using a sequence of edges.

EG: could get from 1 to 3 circuitously as follows:

1-e12-e11-e33-e42-e62-e52-e43

1 2

3 4

e1

e3

e2

e4e5

e6

e7

Page 16: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Paths

A path in a graph is a continuous way of getting from one vertex to another by using a sequence of edges.

EG: could get from 1 to 3 circuitously as follows:

1-e12-e11-e33-e42-e62-e52-e43

1 2

3 4

e1

e3

e2

e4e5

e6

e7

Page 17: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Paths

A path in a graph is a continuous way of getting from one vertex to another by using a sequence of edges.

EG: could get from 1 to 3 circuitously as follows:

1-e12-e11-e33-e42-e62-e52-e43

1 2

3 4

e1

e3

e2

e4e5

e6

e7

Page 18: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Paths

A path in a graph is a continuous way of getting from one vertex to another by using a sequence of edges.

EG: could get from 1 to 3 circuitously as follows:

1-e12-e11-e33-e42-e62-e52-e43

1 2

3 4

e1

e3

e2

e4e5

e6

e7

Page 19: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Paths in Real (CS) World Linkedin paths (let us see in practice) Facebook paths Internet paths …

Lecture 5.4 -- Paths and Connectivity

Page 20: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Paths and Isomorphism Paths and circuits can also be serve as a

good criteria for determining whether two graphs are isomorphic

Look for (simple) circuits of different lengths. Example below:

u1

u6

u2

u3u5

u4Lecture 5.4 -- Paths and

Connectivity

Page 21: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Number of Paths of Certain Lengths Adjacency matrix A for a graph depicts

all paths of length 1 The matrix A2 depicts number of paths

of length 2 In general, the matrix Ak depicts

number of paths of length k

Lecture 5.4 -- Paths and Connectivity

a

d c

b

0110

1001

1001

0110

A

Page 22: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Number of Paths of Certain Lengths Adjacency matrix A for a graph depicts

all paths of length 1 The matrix A2 depicts number of paths

of length 2 In general, the matrix Ak depicts

number of paths of length k

Lecture 5.4 -- Paths and Connectivity

a

d c

b

2002

0220

0220

2002

0110

1001

1001

0110

0110

1001

1001

0110

2A

Page 23: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

ConnectivityDEF: Let G be a pseudograph. Let u and v

be vertices. u and v are connected to each other if there is a path in G which starts at u and ends at v. G is said to be connected if all vertices are connected to each other.

Note: Any vertex is automatically connected to itself via the empty path.

Lecture 5.4 -- Paths and Connectivity

Page 24: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Q: Which of the following graphs are connected?

Connectivity

1 2

34

Lecture 5.4 -- Paths and Connectivity

Page 25: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

A: First and second are disconnected. Last is connected.

Connectivity

1 2

34

Lecture 5.4 -- Paths and Connectivity

Page 26: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

A: First and second are disconnected. Last is connected.

Connectivity

1 2

34

Lecture 5.4 -- Paths and Connectivity

Page 27: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

A: First and second are disconnected. Last is connected.

Connectivity

1 2

34

Lecture 5.4 -- Paths and Connectivity

Page 28: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

A: First and second are disconnected. Last is connected.

Connectivity

1 2

34

Lecture 5.4 -- Paths and Connectivity

Page 29: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

A: First and second are disconnected. Last is connected.

Connectivity

1 2

34

Lecture 5.4 -- Paths and Connectivity

Page 30: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

A: First and second are disconnected. Last is connected.

Connectivity

1 2

34

Lecture 5.4 -- Paths and Connectivity

Page 31: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

English Connectivity PuzzleCan define a puzzling graph G as follows:V = {3-letter English words}E : two words are connected if we can get

one word from the other by changing a single letter.

One small subgraph of G is:

Q: Is “fun” connected to “car” ?

jobrob jab

Lecture 5.4 -- Paths and Connectivity

Page 32: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

English Connectivity PuzzleA: Yes: funfanfarcar

Or: funfinbinbanbarcar

Lecture 5.4 -- Paths and Connectivity

Page 33: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Some Little Theorems

Thm1: Every connected graph with n vertices has at least n-1 edgesProof: Use proof by mathematical inductionBasis Step (n=1): No. of edges is 0, which is less >= 0 (n-1)Induction Step: Assume to be true for n = k and show it to be true for n = k + 1We assumed that a connected graph with k vertices will have at least k–1 edges. Now, we add a new vertex to this graph to obtain a new graph with k vertices. For the new graph to remain connected, the new vertex should be incident with at least one edge which is also incident with one of the vertices in the old graph. This means that the new graph should have a total of at least (k – 1) + 1 = k edges.This proves the induction step.Finally, combining the basis and induction steps, we get that the theorem is true for all n

Page 34: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Some Theorems

Thm 2: Vertex connectedness in a simple graph is an equivalence relationProof: We will show that the “connectedness” relation is reflexive, symmetric and transitiveIt is reflexive since every vertex is connected to itself via a path of length 0It is symmetric because if a vertex u is connected to another vertex v, then there exists a path between u and v – just traverse the reverse pathIt is transitive because if u and v are connected (via path p) and v and w are connected (via path q), then u and w are connected via a path p|q

Page 35: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Some Theorems Thm 3: If a connected simple graph G is

the union of graphs G1 and G2, then G1 and G2 must have a common vertex

Proof: (very simple) let’s use the board.

Lecture 5.4 -- Paths and Connectivity

Page 36: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Connected ComponentsDEF: A connected component (or just

component) in a graph G is a set of vertices such that all vertices in the set are connected to each other and every possible connected vertex is included.

Q: What are the connected components of the following graph?

6 2

435

1

78

Lecture 5.4 -- Paths and Connectivity

Page 37: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Connected ComponentsA: The components are {1,3,5},{2,4,6},

{7} and {8} as one can see visually by pulling components apart:

6 2

4

7835

1

Lecture 5.4 -- Paths and Connectivity

Page 38: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Connected ComponentsA: The components are {1,3,5},{2,4,6},

{7} and {8} as one can see visually by pulling components apart:

6 2

4

7 835

1

Lecture 5.4 -- Paths and Connectivity

Page 39: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Connected ComponentsA: The components are {1,3,5}, {2,4,6},

{7} and {8} as one can see visually by pulling components apart:

6 2

4

7 8

35

1

Lecture 5.4 -- Paths and Connectivity

Page 40: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Degree of ConnectivityNot all connected graphs are treated equal! Q: Rate following graphs in terms of their

design value for computer networks:

1)

2)

3)

4)

Page 41: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Degree of Connectivity

A: Want all computers to be connected, even if 1 computer goes down:

1) 2nd best. However, thereis a weak link— “cut vertex”2) 3rd best. Connectedbut any computer can disconnect 3) Worst! Already disconnected4) Best! Network dies only with 2 bad computers

Lecture 5.4 -- Paths and Connectivity

Page 42: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Degree of Connectivity

The network is best because it can only become disconnected when 2 vertices are removed. In other words, it is 2-connected. Formally:

DEF: A connected simple graph with 3 or more vertices is 2-connected if it remains connected when any vertex is removed. When the graph is not 2-connected, we call the disconnecting vertex a cut vertex.

Lecture 5.4 -- Paths and Connectivity

Page 43: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Degree of Connectivity

There is also a notion of N-Connectivity where we require at least N vertices to be removed to disconnect the graph.

Lecture 5.4 -- Paths and Connectivity

Page 44: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Connectivity inDirected GraphsIn directed graphs may be able to find a

path from a to b but not from b to a. However, Connectivity was a symmetric concept for undirected graphs. So how to define directed Connectivity is non-obvious:

1) Should we ignore directions?2) Should we insist that we can get from

a to b in actual digraph?3) Should we insist that we can get from

a to b and that we can get from b to a?

Lecture 5.4 -- Paths and Connectivity

Page 45: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Connectivity inDirected Graphs

Resolution: Don’t bother choosing which definition is better. Just define to separate concepts:

1) Weakly connected : can get from a to b in underlying undirected graph

2) Semi-connected (my terminology): can get from a to b OR from b to a in digraph

3) Strongly connected : can get from a to b AND from b to a in the digraph

DEF: A graph is strongly (resp. semi, resp. weakly) connected if every pair of vertices is connected in the same sense.

Lecture 5.4 -- Paths and Connectivity

Page 46: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Connectivity inDirected Graphs

Q: Classify the connectivity of each graph.

Lecture 5.4 -- Paths and Connectivity

Page 47: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Connectivity inDirected Graphs

A: semi weak strong

Lecture 5.4 -- Paths and Connectivity

Page 48: Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag

Lecture 5.4 -- Paths and Connectivity

Today’s Reading Rosen 10.3 and 10.4

Little work will not hurt!